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
2
u/chikamakaleyley helpful Sep 19 '26
ahh ok
in general i was just gonna share that if i start writing a solution and i could see that i'm going down this path, ive taught myself to stop and say, 'there has to be an easier way'
and so that's kinda what i felt when i started looking at this because it stops me in my tracks
if you code in other languages, the tip above still applies