javascript - If variable equals the number 1 -
i'm trying write simple if statement in jquery. if variable equals number 1 this, if equals number 2 this. wrote doesn't seem work , can't figure out why:
$("#next-btn").click(function() { if (current_slide = 1) { first_screen(); }, else if (current_slide = 2) { second_screen(); } });
probably simple, appreciate help.
you need use comparison operator ==
in if statement condition instead of assignment operator =
remove comma
after first closing curly bracket of then
(true) block of if
statement. can test on here.
if (current_slide == 1) { first_screen(); } else if (current_slide == 2) { second_screen(); }
i assume current_slide has number compare, read below how comparison operator == performs comparison.
comparion equal operator
if 2 operands not of same type, javascript converts operands applies strict comparison. if either operand number or boolean, operands converted numbers if possible; else if either operand string, other operand converted string if possible. if both operands objects, javascript compares internal references equal when operands refer same object in memory, reference.
Comments
Post a Comment