The snippets of JavaScript below contain syntax errors andor

The snippets of JavaScript below contain syntax errors and/or logic errors. Identify the errors and insert your corrected code.

a-

function main()

{

    var score;

    score = getScore(score);

    displayGrade(score);

}

                          function getScore (score)

{

    score = Number(prompt(\"Enter your exam score\"));

    return score;

}

function displayGrade (score)

{

            if (score < 70)

            {

                console.log(\"You have earned a satisfactory grade (C or better)\");

            }

            else

            {

                console.log(\"You have earned an unsatisfactory grade (D or lower)”);

             }

            }
            main();

b-

function main()

      {

          var salary;

          salary = Number(prompt(\"Enter your yearly salary \"));

          if (salary < 20000)

          {

                  console.log(\"You are in the lowest salary range \");

          }

          if (salary < 40000)

          {

                  console.log(\"You are in the middle salary range \");

          }

          else

          {

                  console.log(\"You are in the highest salary range \");

          }

    }

    main();

c-

function main()

      {

          var course= prompt(\"Enter the name of your computer course \");

          if (course = \"COMP-101 \")

          {

                  console.log(\"That is a great course \");

          }

    }

    main();

d-

function main()

      {

          var age;

          age = Number(prompt(\"Enter your age \"));

          if age > 20 then

          {

                  console.log(\"You are older than 20 years \");

          }

    }

    main();

f-

function main()

      {

          var total;    

                 var total = Number(prompt(\"Enter your total \"));

                 if (total > 100)

      console.log(\"You have scored over 100% \");

                 end if

      }

    main();

Solution

Quetion a:

function main()
{
var score;
score = getScore(score);
displayGrade(score);
}
function getScore (score)
{
score = Number(prompt(\"Enter your exam score\"));
return score;
}
function displayGrade (score)
{
if (score > 70)
{
console.log(\"You have earned a satisfactory grade (C or better)\");
}
else
{
console.log(\"You have earned an unsatisfactory grade (D or lower)”);
}
}

main();

Question b:

function main()

      {

          var salary;

          salary = Number(prompt(\"Enter your yearly salary \"));

          if (salary < 20000)

          {

                  console.log(\"You are in the lowest salary range \");

          }

          if (salary >= 20000 && salary < 40000)

          {

                  console.log(\"You are in the middle salary range \");

          }

          else

          {

                  console.log(\"You are in the highest salary range \");

          }

    }

    main();

Question c:

function main()

      {

          var course= prompt(\"Enter the name of your computer course \");

          if (course == \"COMP-101 \")

          {

                  console.log(\"That is a great course \");

          }

    }

    main();

Question d:

function main()

      {

          var age;

          age = Number(prompt(\"Enter your age \"));

          if (age > 20)

{

                  console.log(\"You are older than 20 years \");

          }

    }

    main();

Question f:

function main()

      {

          var total;    

                 var total = Number(prompt(\"Enter your total \"));

                 if (total > 100) {

      console.log(\"You have scored over 100% \");

}

      }

    main();

The snippets of JavaScript below contain syntax errors and/or logic errors. Identify the errors and insert your corrected code. a- function main() { var score;
The snippets of JavaScript below contain syntax errors and/or logic errors. Identify the errors and insert your corrected code. a- function main() { var score;
The snippets of JavaScript below contain syntax errors and/or logic errors. Identify the errors and insert your corrected code. a- function main() { var score;
The snippets of JavaScript below contain syntax errors and/or logic errors. Identify the errors and insert your corrected code. a- function main() { var score;
The snippets of JavaScript below contain syntax errors and/or logic errors. Identify the errors and insert your corrected code. a- function main() { var score;

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site