Q:

Write a JavaScript program to check whether a string starts with 'Java' and false otherwise

0

 Write a JavaScript program to check whether a string starts with 'Java' and false otherwise.

All Answers

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

function start_spec_str(str)
{
  if (str.length < 4)
  {
    return false;
  }
  front = str.substring(0, 4);
  if (front == 'Java') 
  {
    return true;
  }
   else 
   {
    return false;
  }
}

console.log(start_spec_str("JavaScript"));
console.log(start_spec_str("Java"));
console.log(start_spec_str("Python"));

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