My if ever falls on Is

Asked

Viewed 115 times

-5

I need to turn down the volume of <audio> by clicking the arrow below, but the if is not working, never gets into the else. Why?

Code:

$(document).keyup(function(e) {
    if (e.keyCode == 40) { 

if ($("#nome").get(0).volume = 0.1)
{
    $("#nome").prop('muted', true);
}
else if ($("#nome").get(0).volume = 0.4)
{
    $("#nome").prop("volume", 0.1);
}

     }
});
  • 2

    Why are you negatively asking the question, why ?

  • 4

    @Fulvius I think it is because the problem seems to have been caused by a distraction (see correct use of == in the if outsider).

  • I agree with you @bfavaretto of the error, that’s it, but the intention is not to point out the errors? Or not?

  • 1

    @Fulvius One of the main goals of the site is to be a great repository of questions and answers, ideally useful for more than one person. So the more chance the question has of serving future visitors, who arrive here by Google, the better. In this sense, syntax errors like this are not good candidates. I edited the title with this in mind.

  • 1

    Got it @bfavaretto

  • It’s time to mark the question as resolved

  • @Wallacemaxters I’m thinking of closing... but I’m in doubt, because this kind of mistake is up to that common.

Show 2 more comments

1 answer

6

You are using = instead of == (an assignment instead of comparison):

if ($("#nome").get(0).volume == 0.1)
{
    $("#nome").prop('muted', true);
}
else if ($("#nome").get(0).volume == 0.4)
{
    $("#nome").prop("volume", 0.1);
}
  • 1

    vlw!!!!!!!!!!!!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.