+ 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 Answers
+ 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