+ 1

Node js question

if ( i % 3 === 0 ) { deretTask += 'Solo' } else if (i % 5 === 0) { deretTask += 'Learn' } how about the code if the number can % by 3 and 5 ? if the number can % by 3 and 5 add to the deretTask variable as 'Solo Learn'

3rd Nov 2018, 3:38 PM
Kenzo Akbar
Kenzo Akbar - avatar
2 Respostas
+ 1
Probably try something like this? let mod3 = i % 3; let mod5 = i % 5; if(mod3 === 0 && mod5 === 0) { // divisible by 3 and 5 deretTask += "Solo Learn"; } else { if(mod3 === 0) { // divisible by 3 deretTask += "Solo"; } else if(mod5 === 0) { // divisible by 5 deretTask += "Learn"; } }
3rd Nov 2018, 4:05 PM
Ipang
0
I propose: if ( i % 3 === 0 ) { deretTask += 'Solo' } if (i % 5 === 0) { deretTask += 'Learn' } I don’t know if you need a space between. If so, you could use instead: if (i % 5 === 0) { if (i % 3 === 0) deretTask += ' ' deretTask += 'Learn' }
3rd Nov 2018, 4:16 PM
mimtelf
mimtelf - avatar