0
Not sure what’s wrong with this code (JavaScript)
function main() { var numberVolunteers = parseInt(readLine(), 10) // Your code here var x = numberVolunteers%5; var y = 5 - x ; console.log(y); }
7 Antworten
+ 2
I have never seen readLine() use in js but I do come across people on this platform using it ,can you please give me source to read about the usage of readLine()?
+ 1
its a question in the course exercise.
Volunteers have been divided into 5 groups with equal number of members. If any group has fewer than 5 people, more volunteers must be recruited to fill the positions.
Write a program that takes the number of volunteers and outputs to the console how many volunteers need to be hired to have 5 equal groups.
Sample Input
24
Sample Output
1
Explanation
The nearest number to 24 that is multiple of 5 is 25, so we need 1 more volunteer (24+1=25) to get 5 equal groups.
need to use the modulus moderator % . i entered the coding after //Your code here. but i am trying to see whats wrong with that code
+ 1
i see, i understand now , need to seperare the zero and non zero case. thank you so much!!!
0
Cheri Yan i am talking about readLine() method in JavaScript since you have tagged Javascript ,I am sure these exercises uses node which allows execution of JavaScript outside browser ,
Here is the only readLine() module I have found in various searches
https://www.google.com/url?sa=t&source=web&rct=j&url=https://nodejs.org/api/readline.html&ved=2ahUKEwjlwoyim9LsAhUg6XMBHSIKC78QFjAAegQIARAB&usg=AOvVaw1kx1u0u8EqUN9WwYIxiNH7&cshid=1603713788051
Anyway assuming readLine() works here in node ,I will see what other error you might be getting
0
thanks for the link. yes i am assuming the readLine() works, pls let me know if you spot anything. thanks
0
Cheri Yan
This should work
If you get 0 as remainder meaning the number of volunteers are equally distributed so you don't need to do 5-remainder
function main() {
var numberVolunteers = parseInt(readLine(), 10)
// Your code here
var x = numberVolunteers%5;
if(x!=0){
var y = 5 - x ;
}
else{
var y=0;
}
console.log(y);
}
0
👍