Help! How do I make something like | (p<=5, p>=3) | work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help! How do I make something like | (p<=5, p>=3) | work?

Okay, so I'm trying to make a Trivia game and in this game, you earn a point when you get a question right, and you lose a point if you get a question wrong. In the end, I'm trying to make different outcomes, depending on how many points you have. So below, I have it so if you have points less than or equal to 2, it prints (You did absolutely terrible. You scored " + p + " points), and if you have greater than 5 points it prints (You did very well. You scored " + p + " points!) I want to make it so that if you have points through 5-3(at the very bottom) it will print (You did kind of okay. You scored " + p + " points). But it is not working, so how can I do this? if (p<=2) { alert("You did absolutely terrible. You scored " + p + " points."); } if (p>5) { alert("You did very well. You scored " + p + " points!"); } if (p<=5, p>=3) { <================== alert("You did kind of okay. You scored " + p + " points."); } }

2nd Aug 2017, 11:09 PM
Akili KiKi
Akili KiKi - avatar
3 Answers
+ 2
You have to place a &&(AND) like this: if(p<=5 && p>=3) { //your code }
2nd Aug 2017, 11:35 PM
Dr_Donko89
Dr_Donko89 - avatar
+ 3
In this special context, you can do simpler: if (p<=2) { alert("You did absolutely terrible. You scored " + p + " points."); } else if (p>5) { alert("You did very well. You scored " + p + " points!"); } else { <================== alert("You did kind of okay. You scored " + p + " points."); } :P
3rd Aug 2017, 5:38 AM
visph
visph - avatar
0
Oh yeah! I remember now. Thanks mate
3rd Aug 2017, 1:29 AM
Akili KiKi
Akili KiKi - avatar