0

JS exercise 10.4

Hi there! In the exercise 10.4 we're supposed to use the % operator to basically check if the number is divided by zero. Here's the 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 empty spots. 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. */ The only solution presented is with ? : - which we haven't learned at this point in this course, so I'm trying and would like to solve it with if, but can't seem to do it. Could anyone help me here? Thanks!

26th Mar 2022, 10:57 AM
KitTheCat
3 Respostas
+ 3
Where did you define neededVolunteers() function?
26th Mar 2022, 11:15 AM
Simba
Simba - avatar
0
This is what I got so far, not working: function main() { var numberVolunteers = parseInt(readLine(), 10) if neededVolunteers = numberVolunteers % 5 == 0 { return console.log("the teams are complete") } else { return console.log("we need more volunteers") } }; } console.log(neededVolunteers())
26th Mar 2022, 11:05 AM
KitTheCat
0
Oh, you're totally right! I hadn't called the function with its proper name, but I still couldn't get it right! function main() { var numberVolunteers = parseInt(readLine(), 10) var = neededVolunteers; if (neededVolunteers = numberVolunteers % 5 == 0); } console.log(main())
26th Mar 2022, 3:21 PM
KitTheCat