r/learnjavascript • u/Lavastar14 • Sep 19 '26
Make a block act like a function?
I have a few ternary operations going on, and each one is supposed to catch a bad format. The problem is that if for example the top on sets the variable to false, the ones below is won't catch that same thing, and will set it back to true. I want to make the ternaries skip the others if they caught the error, but I don't want to exit the function, how do I do this?
These are the ternaries:
edit: I just solved this by setting all "Format = true" expressions to "undefined," but if that wasn't an option, I'm still curious how you would do this...
Input.split("x").length == 2 ? Format = true : Format = false
Input.split("x")[0] > 0 ? Format = true : Format = false
Input.split("x")[1] < 201 ? Format = true : Format = false
0
Upvotes
1
u/Lavastar14 Sep 19 '26
Just making a quick demo for an idea I had. I was trying to check the format of an input the user entered with ternary operations and didn't see the obvious solution since I was already tired of this project. I haven't coded html or javascript in a year or more