How do you end certain code if a condition is true or false in JavaScript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do you end certain code if a condition is true or false in JavaScript?

Hi, this is my first post, I hope you like it! https://code.sololearn.com/WNhn4QxPL09P/?ref=app

14th Nov 2017, 8:17 AM
The C0der
The C0der - avatar
4 Answers
+ 1
You can use 'return;' to end the running function. Plus, you can return data if it's called with another function, like return true; or return 'the process was stopped';
14th Nov 2017, 9:59 AM
dunfc
dunfc - avatar
+ 4
break; if you mean loops
14th Nov 2017, 8:18 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
I don't mean in loops I mean a if condition is true.
14th Nov 2017, 8:20 AM
The C0der
The C0der - avatar
+ 1
Just don't execute any code after that. Place the password request and check, inside the if-statements valid outcome. Use this logic (I don't advise using this type of code, but I'm not going to do your work for you :P) if (userValid){ if (passValid){ alert("shit checks out"); } else { alert("incorrect"); } } else { alert("incorrect"); }
14th Nov 2017, 8:48 AM
eRosz
eRosz - avatar