+ 1

Boolean?

So I'm trying to make a program with js that toggles a var between true and false with a button, and prints true or false to the screen, but I can't get it to work. Can somebody help me? (There's no code to share since I never saved one)

18th Jun 2018, 2:54 AM
Daniel Cooper
Daniel Cooper - avatar
5 Answers
18th Jun 2018, 3:05 AM
Nikhil
Nikhil - avatar
+ 10
It should work.. Showing your code will help a lot. https://code.sololearn.com/W9Oq60hWWBQJ/?ref=app
18th Jun 2018, 4:13 AM
Nikhil
Nikhil - avatar
+ 1
I was trying if(boolean variable) { //code to be executed if var is true } else { //code to be executed if var is false } but it wouldn't work. Why not?
18th Jun 2018, 4:07 AM
Daniel Cooper
Daniel Cooper - avatar
+ 1
Figured out why it didn't work. Here's the code with a comment explaining my mistake. https://code.sololearn.com/WSPW5b4j0TML/?ref=app
18th Jun 2018, 4:19 AM
Daniel Cooper
Daniel Cooper - avatar
+ 1
As it turns out, the Javascript course actually explains boolean operators and either I forgot, or it was added in after I completed the course. But chances are, I forgot. xD
18th Jun 2018, 4:27 AM
Daniel Cooper
Daniel Cooper - avatar