+ 2

Condition, term etc.

Colleagues, this is simple question for masters, but I’m not the one of them. I’ve got stuck in it. The task includes condition: if x=5, then “x” must to be changed into “0”. var x = (5 - (x % 5)); if (x === 5) ( '0' ); console.log (x); How should I write this code properly and not to broke the first line? Please help!

21st Jul 2021, 1:14 AM
Роман Рубцов
7 ответов
+ 6
if (x == 5) x = 0 ?
21st Jul 2021, 1:24 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
try this if (x === 5){ x = 0; } console.log(x);
21st Jul 2021, 1:39 AM
Muhammad Alwan
Muhammad Alwan - avatar
+ 1
Where do you get this expression x = 5-(x%5) => 5-x = x%5 Which will not satisfied by any value of 0<= x<= infinite What does it mean..
21st Jul 2021, 2:43 AM
Divya Mohan
Divya Mohan - avatar
+ 1
It’s the task in JS learning. We have some groups of people wich consist of different number (0, 14, 3 20 and so long). Each number has to be divided in minor groups (everyone of 5 men). The code must to test every number and show hom many people we need to add for this number could be divided by 5. If the answer is “0”, the code must show “0”.
21st Jul 2021, 6:10 AM
Роман Рубцов
+ 1
If you mean that you have remake the given uneven groups into groups of five member in each, you can add all the numbers and modulo with five it will give how much people left.
21st Jul 2021, 6:16 AM
Divya Mohan
Divya Mohan - avatar
+ 1
Thank you all for help! It’s working!
21st Jul 2021, 6:21 AM
Роман Рубцов
0
myjj7nrbqsSFgXR
25th Jul 2021, 11:18 PM
Eliza Żelazna
Eliza Żelazna - avatar