Lowest price ever! Learn Generative AI for 48% less!
Get my discount+ 1
How do I use booleans with conditional statements in javascript?
This case I want it when 7 is typed it should show can’t use such name but when other numbers are typed it should show wick <label>nme</label> <input id="o" type="number" placeholder="your name" required> <button onclick="f()" > calculate </button> function f() { var o = 7; document.getElementById("o").value; if (o == 7) { alert("cant you such name"); } else if (o === 7 ) { alert ("wick"); } else { alert("leave"); } }
9 Answers
+ 5
var o = document.getElementById("o").value.
var o = 7 will make o always be 7!
+ 3
how do you mean?
if blocks are booleans
if true do this
else do that // false
if !true do this
else do that // true
if false do this
else do that // true
if !false do this
else do that // false
They use boolean operators too like
a > b
a >= b
a < b
a <= b
a != b
a == b
a === b // JAVASCRIPT ONLY
a || b // if any is true
a && b // if both are true
etc.
+ 2
Happy to help! :)
+ 2
Sorry if this is late, slept early :p
o.toString();
or
"" + o;
+ 2
idk much python but in javascript you have to have if-else if-else in order to check. cant be excluded
+ 1
Thanks , it worked
0
How do I use alphabet instead of numbers ?
0
how can we replace if statement blocks with boolean?
0
like boolean in python. and, or, not in place of if and elif. so can we do that?