Intermediate Algorithm Scripting - Drop it

Hello everyone, i was trying to solve some challenge (not a FCC challenge).

The full code is below, i need help in this line specifically:

// the code i wrote, the solution i think is correct
 else {
    who += "no one likes this";
    return who;
  }

console.log(likes([])); // 'no one likes this' 

// the input, and the comment is what i want the result to be.

// i tried writing:
If (Names.length === 0) {
Return “no one likes it”; }

// and

If (Names.length < 1) {
Who += “no one likes it;
return who; }

————————-

const likes = Names => {
  let who = "";
for (let B in Names) {
  if (Names.length === 1) {
who += Names[B] + " likes this";
return who;
  } else if (Names.length === 2) {
    who += Names[0] + " and " + Names[1] + " like " + "this";
    return who;
  } else if (Names.length === 3) {
  who += Names[0] + ", " + Names[1] + " and " + Names[2] + " like " + "this";
  return who;
  } else if (Names.length > 3) {
    let yes = Names.length - 2;
  who += Names[0] + ", " + Names[1] + " and " + yes + " others like this";
  return who;
  } else {
    who += "no one likes this";
    return who;
  }
}
};

console.log(likes([])); // 'no one likes this'
console.log(likes(['Peter'])); // 'Peter likes this'
console.log(likes(['Jacob', 'Alex'])); // 'Jacob and Alex like this'
console.log(likes(['Max', 'John', 'Mark'])); // 'Max, John and Mark like this'
console.log(likes(['Alex', 'Jacob', 'Mark', 'Max'])); // 'Alex, Jacob and 2 others like this'

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Safari/605.1.15

Challenge Information:

Intermediate Algorithm Scripting - Drop it

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.