Unable to find error in my jquery progaram


#1

var main = function(){

$("#item").change(function(){
if($(this).val() === "food"){
$("#cost").val("100");
}

else if($(this).val() ==="fish oil"){
 $("#cost").val("100");
}
else {
 $("#cost").val("250");
}

});

var cost =$("cost").val();
var totalamount;

$("input:radio[name='discount']").change(function(){
 if ( this.checked && value =="5"){
    totalamount = cost-cost*5/100;
 }
 else
 {
    totalamount == cost-cost*10/100;
 }
});

 $("calculate").click(function(){

$("totalcost").val(totalamount);

});

i have created the total amount calculating software i dont know why my code is not working please help me


#2

@nesu123,
Looking over the code presented

-1

You should modify the jQuery-Selectors
$("cost")
$("calculate")
$("totalcost")

-2

When defining a =main= function
you should use a closing-curly-bracket-}
like

var main = function() {
       //Begin of the FUNCTION-BODY

       //All of your code

       //End of the FUNCTION-BODY
     };

-3

The =main= function should be executed.....
The best possible moment
to execute the =main= function
is when your HTML-Document is fully loaded.

jQuery provides you with a ready() method
which you use like

$(document).ready( main );

and should be placed AFTER the =main= function definition.....

===============================================

Out of curiosity,
could you provide us the HTML-code you are using.


#4

sir , i think i have modified jquery selectors and corrected errors but still it is not working


#5

@nesu123,
Present the HTML code
and the JS/Jquery code you are actually using....

edit your Post

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

or even better use
= http://discuss.codecademy.com/t/using-backticks-to-format-your-code/3697/2
[extra's]
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet


#6