jeudi 26 septembre 2019

how to write a function in javascript that transforms multiple of 3 into a string

When a number is a multiple of 3 i want to change it to a string "Menthe", when it's a multiple of 5 to "Glace", when it's a multiple of 7 to "Rhum,.

results need to be numbers from 1 to 110, 11 numbers per line like this :

1 2 Menthe 4 Glace Menthe Rhum 8 Menthe Glace 11

Menthe 13 Rhum MentheGlace 16 17 Menthe 19 Glace MentheRhum 22

23 Menthe Glace 26 Menthe Rhum 29 MentheGlace 31 32 Menthe

I haave to use 2 parameters also startOfCount, endOfCount which I didn't understand their utility This is what I have done so far but how to create the list of numbers and how to put in the loop thank you:

function mojitor(startOfCount, endOfCount) {
for (var x=1; x <= 110; x++){
    if( x % 3 == 0 ){
        return "Menthe"
    }
    if( x % 5 == 0 ){
        return "Glace"
    }
    if( x % 7 == 0 ){
        return "Rhum"
    }
    if( ( x % 3 == 0 ) && ( x % 5 == 0 ) ){
        return "MentheGlace"
    }
        if( ( x % 3 == 0 ) && ( x % 5 == 0 )&& ( x % 7 == 0 ) ){
        return "Mojito"
    }
}
}

Aucun commentaire:

Enregistrer un commentaire