0

Can anyone help me with this code in Java Script

JS The if else statement Entrance to the club is only permitted in pairs. Take the number of customers in the club as input, and, if all of them have a pair, output to the console "Right", otherwise output "Wrong". Sample Input 14 Sample Output Right function main() { var numberGuests = parseInt(readLine(), 10) // Your code here if (numberGuests % 2) == 0) { console.log("Right") } else { console.log("Wrong") } main() }

5th Oct 2021, 9:44 AM
Sean Taylor
Sean Taylor - avatar
9 odpowiedzi
+ 4
It's not necessary to call main() in Js practices since it's done by the compiler itself.
5th Oct 2021, 10:16 AM
Simba
Simba - avatar
+ 3
Open parenthesis is missing in if It should be if((numberGuests % 2) == 0){ .... } And you can also do this with a single pair of parenthesis if (numberGuests % 2 == 0){ ..... }
5th Oct 2021, 9:49 AM
Rupali Haldiya
Rupali Haldiya - avatar
+ 2
You need to use logical operators to combine two or more conditions else if (score >= 40 && score <= 87){ console.log("good") }
5th Oct 2021, 10:42 AM
Simba
Simba - avatar
+ 2
(score = 40 - 87), it will set the score to -47, and if the score is not greater than 88, then this condition ,(score = 40 - 87), will be always true.
5th Oct 2021, 10:46 AM
Rupali Haldiya
Rupali Haldiya - avatar
+ 1
Thanks so much eveyone that fixed my code !! I have another question about a different challege, I have written a code for exam results and its working for "excellent" and "good" but its not working on the "fail" test case. It outputs "good" for a score of 18 for some reason: else if Тhe result of an exam will be determined as follows։ If the score is 88 and above => excellent 40-87 => good 0-39 => fail You are given a program that takes the score as input. Task Complete the code to output the corresponding result (excellent, good, fail) to the console. Sample Input 78 Sample Output good var score = parseInt(readLine(), 10) /* 88 and above => excellent 40-87 => good 0-39 => fail */ // your code goes here if (score >= 88) { console.log("excellent") } else if (score = 40-87) { console.log("good") } else { console.log("fail") }
5th Oct 2021, 10:38 AM
Sean Taylor
Sean Taylor - avatar
+ 1
Thank you Simba && Rupali ;-)
5th Oct 2021, 10:51 AM
Sean Taylor
Sean Taylor - avatar
0
Sean Taylor you're welcome 8D
5th Oct 2021, 10:53 AM
Rupali Haldiya
Rupali Haldiya - avatar
0
In your code, you have an unmatched bracket : function main() { var numberGuests = parseInt(readLine(), 10) // Your code here if(numberGuests % 2 == 0) { console.log("Right") } else { console.log("Wrong") } }
6th Oct 2021, 11:50 AM
Ikenna Eze
0
One liner ? : const main = () => console.log(+readLine() % 2 === 0 ? "Right" : "Wrong")
6th Oct 2021, 9:13 PM
Cdc_429_laB
Cdc_429_laB - avatar