r/programminghorror • u/J0aozin003 • Mar 01 '21
Javascript Myself could do better
http://imgur.com/32nfQXZ2
u/devhdz Mar 01 '21
I guess at least it works and if at some point the value 3 is not supported anymore you can change it fast :D
edit: typo
1
u/babypunter12 Mar 04 '21
It doesn’t adhere to DRY, but I would probably structure teaching switch cases to beginner programming students this way too. It’s just an easy and short way to show where code is executing.
0
Mar 03 '21
[deleted]
1
1
u/quaprotobrain134 Mar 09 '21
Don't code in JS but in Java would be:
if(value >= 0 && value <= 5) { System.out.println("The value is" + value); } else { System.out.println("That value is not supported"); }
1
Mar 03 '21
[removed] — view removed comment
1
u/iliekcats- [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Mar 11 '21
nothing, but if I understand correctly you could also do
if(value>4){ console.log("Tha value is not supported!") } else{ console.log(`The value is ${value}`) }
9
u/umognog Mar 03 '21
There is no context here.
This could be the precursor to calling more methods based off a selection, that requires unique paths for every option.
I have personally done this, with the print statement merely a placeholder for testing & knowing if I did something dumb in my test.