+ 2
If else..... JavaScript
Can anyone please tell me whatâs wrong..... the conditions are not outputting. âuse strict'; x = 3 let test; if(x>=8) {test = "Oh B it works!";} else{ test = "oops its doesn't" ;} console.log(test);
6 Answers
+ 3
"use strict"; // use double quotes not single quotes
let x = 3;
// Undefined variable <x> triggers error in strict mode
// https://www.w3docs.com/learn-javascript/javascript-use-strict.html
let test;
if( x >= 8 )
{
test = "Oh B it works!";
}
else
{
test = "oops its doesn't" ;
}
console.log(test);
+ 3
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#converting_mistakes_into_errors
1. this is because of Strict mode
2. You are Using two Different Quotes on "use strict"
3. You forgot to give var or let or const keyword
Using strict mode it will not allow to use x globally
for example
"use strict"
x = 20;
will throw an error
but if u don't use strict it wil not throw any error
x = 20
no errors
+ 1
Ipang Thank you for responding
0
Pariket Thakur Very helpful, thank you
0
đ±đđđđđđđ I tried your code suggesstion, didnât return the right âresultâ