+ 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);

8th Feb 2022, 5:02 PM
Blessing Ene Anyebe
Blessing Ene Anyebe - avatar
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);
8th Feb 2022, 5:16 PM
Ipang
+ 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
8th Feb 2022, 5:18 PM
Pariket Thakur
Pariket Thakur - avatar
+ 1
Ipang Thank you for responding
8th Feb 2022, 5:34 PM
Blessing Ene Anyebe
Blessing Ene Anyebe - avatar
0
Pariket Thakur Very helpful, thank you
8th Feb 2022, 5:32 PM
Blessing Ene Anyebe
Blessing Ene Anyebe - avatar
0
đ•±đ–Žđ–—đ–Šđ–†đ–—đ–’đ–˜ I tried your code suggesstion, didn’t return the right “result”
8th Feb 2022, 5:34 PM
Blessing Ene Anyebe
Blessing Ene Anyebe - avatar