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

  • برمجة جافاسكربت java script

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

الأجوبة

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"));
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...