Q:

Write a JavaScript program to display the city name if the string begins with "Los" or "New" otherwise return blank

0

Write a JavaScript program to display the city name if the string begins with "Los" or "New" otherwise return blank.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

function city_name(str) {
  if (str.length >= 3 && ((str.substring(0, 3) == 'Los')
                          || (str.substring(0, 3) == 'New')))
   
      {
          return str;
    }

  return '';
}

console.log(city_name("New York"));
console.log(city_name("Los Angeles"));
console.log(city_name("London"));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now