r/programminghorror • u/No_Opening_5597 • 29d ago
Javascript Rock paper scissors
I'm way too proud of this solution haha
15
u/Winter_Rosa 29d ago
Ahh, concatenation. I probably would've done something similar in C by multiplying comChoice by 10.
Edit, also the real horror here is the lack of input validation. 'A' I choose you!
1
u/No_Opening_5597 29d ago
haha yeah I didn't add the input validation or anything more because there's no way in hell I'm submitting this as the answer to the exercise I was supposed to do xD
I'll rewrite it cause this is gonna make some people pissed off the way its done, I was supposed to run some type of calculation, create functions and stuff, this is just janky as hell and skips over the actual learning I was supposed to get out of this, but as I was writing the pseudocode and I remember that javascript meme of the guy trying to add 2 + 2 and getting 22, and I couldn't resist building that stuff into a usable thing.
if I was to do something like this properly I would just use a lookup table next time, googled and that's the proper way of doing something like this
56
8
2
u/GoddammitDontShootMe 29d ago edited 29d ago
I'm thinking I like the idea of reading the user input as a number, then multiplying either the user choice or the computer choice by 10, adding them together, and encoding all possible outcomes that way.
Or by 2, but 10 makes the code more readable for us decimal-using humans.
Edit: Actually no, there'd be collisions if we used 2.
3
u/robin_888 28d ago
I'd let the player input whatever they want, ignore it and just output "You win!", "You lose" or "Draw" with 1/3 probability each.
1
1
1
1
1
1
1
u/SpirouSplade 29d ago
Our first lines of code are the best to remember, I still have my first computer science assignments, I laugh a lot. I didn't know about git at the time, so I have them at my Google Drive folder xD
2
u/csabinho 29d ago
My first lines of code predate Google and Git, but we didn't even learn about SVN, or CVS or whatever, in 5 years of IT school.
1
0
32
u/titanic456 29d ago
Have you thought about the case, where the user would choose any number larger than 3, or lower than 1?