-4

My code does not seem to be working and I'm not sure why, I'm knew to else if statements so maybe I'm doing this completely wrong. I need the user to enter a number and depending on the number they enter a statement is printed out.

Please see my code below, the error message I'm getting is "Undefined" after the user enters the number and presses enter.

let waterPay = prompt("Please enter the amount of water you use to get a price you need to pay, thank you!");

if (waterPay > 6000) {
  console.log("The number is below 6000");
} else if (waterPay(6000 <= 10500)) {
  console.log("The number is between 6000 and 10500");
} else if (waterPay(10.5 <= 35000)) {
  console.log("The number is between 10500 and 35000");
} else(waterPay( <= 35000)) {
  console.log("The number is above 35000");
}
Ivar
  • 6,138
  • 12
  • 49
  • 61
PoisonMaster
  • 27
  • 1
  • 6
  • You should use```(waterPay > 6000 && waterPay <= 10500)``` instead – ikhvjs Jul 19 '21 at 10:04
  • 4
    I'd suggest skimming some JS tutorials or looking around for what if-statement expressions look like--only one of these is correct. – Dave Newton Jul 19 '21 at 10:05
  • huuh?`if (waterPay > 6000) {console.log("The number is below 6000");}` shouldn't this be ""The number is above 6000"" – I_love_vegetables Jul 19 '21 at 10:05
  • 2
    "_I'm getting is "Undefined" after the user enters the number and presses enter._" If you're using the code above, I highly doubt that you get prompted anything at all. It contains several syntax errors. – Ivar Jul 19 '21 at 10:06

2 Answers2

0

From a quick look, it seems that the if-else-if is structured correctly. There appears to be an issue with your comparisons though. For example waterPay (6000 <= 10500) is not valid syntax. You probably want to write waterPay > 6000 && waterPay < 10500

Also make sure all your branches are accessible, ie that conditions don’t overlap

Shmuli
  • 56
  • 6
0

Check out the if...else page on mdn to see the expected syntax.

let waterPay = prompt("Please enter the amount of water you use to get a price you need to pay, thank you!");

if (waterPay < 6000) {
  console.log("The number is below 6000");
} else if (waterPay <= 10500) {
  console.log("The number is between 6000 and 10500");
} else if (waterPay <= 35000) {
  console.log("The number is between 10501 and 35000");
} else {
  console.log("The number is above 35001");
}
ksav
  • 20,015
  • 6
  • 46
  • 66