0

JavaScript if else

Why is there a error?? var height = parseFloat(readLine(), 10) //your goes code here if (height >= 2.45); { console.log ("new record!"); } if else (height >= 2.44) { console.log ('not this time!'); }

23rd Sep 2021, 6:22 PM
Anthony Oliveri
Anthony Oliveri - avatar
10 Answers
+ 3
var height = parseFloat(readLine(), 10) //your goes code here if (height > 2.45) { console.log ('new record') } else if (height < 2.44) { console.log ("not this time") } Good Luck
25th Jan 2022, 7:54 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
+ 2
Remove the (height >= 2.44) part: You only want to know if someone beats the record. If not he/she must me smaller (else)
23rd Sep 2021, 6:46 PM
Lisa
Lisa - avatar
+ 1
1. That else if{} not if else{} 2. remove semicolons on the end of if line var height = parseFloat(readLine(), 10) //your goes code here if (height >= 2.45) { console.log ("new record!"); } else if (height >= 2.44) { console.log ('not this time!'); }
23rd Sep 2021, 6:24 PM
Pariket Thakur
Pariket Thakur - avatar
+ 1
From how I understand your code, I'd suggest to use only "else" on the second part (no "else if")
23rd Sep 2021, 6:29 PM
Lisa
Lisa - avatar
+ 1
Thanks a lot!!
23rd Sep 2021, 6:37 PM
Anthony Oliveri
Anthony Oliveri - avatar
0
Im confused dont i need an if statement?
23rd Sep 2021, 7:09 PM
Anthony Oliveri
Anthony Oliveri - avatar
0
I don't know what the task is (I can't see the pro projects) but I think you need both: if (condition) { ... } else { ... }
23rd Sep 2021, 8:55 PM
Lisa
Lisa - avatar
0
Another issue: If you read the task instruction again, you'll find that it needs to be if (height > 2.45) ... (Not >=)
24th Sep 2021, 9:21 AM
Lisa
Lisa - avatar
0
var height = parseFloat(readLine(), 10) //your goes code here if (height > 2.45) { console.log ('new record') } else if (height < 2.44) { console.log ("not this time") }
25th Nov 2021, 9:11 AM
Milad Ahmad
Milad Ahmad - avatar
0
if(height < 2.45){ console.log("not this time") } else { console.log("new record") }
23rd Mar 2023, 7:08 PM
Daniel