Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Who likes it?

function likes(names) {



    if (names.length === 0) {
        return 'no one likes this'
    }
    else if (names.length === 1) {
        return `${names[0]} likes this`
    }

    else if (names.length === 2) {
        return `${names[0]} and ${names[1]} like this`
    }

    else if (names.length === 3) {
        return `${names[0]}, ${names[1]} and ${names[2]} like this`

    }

    else {
        let pepole = names.length - 2;
        return `${names[0]}, ${names[1]} and ${pepole} others like this`
    }


}
Source by www.codewars.com #
 
PREVIOUS NEXT
Tagged: #Who #likes
ADD COMMENT
Topic
Name
6+2 =