+ 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'
2 Answers
+ 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";
}
}
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'
}