The snippets of JavaScript below contain syntax errors and/or logic errors. Iden
ID: 3669886 • Letter: T
Question
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();
e. function main()
{
var total;
var total = Number(prompt("Enter your total "));
if (total > 100)
console.log("You have scored over 100% ");
end if
}
main();
Explanation / Answer
a. function main()
{
Global 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 ");
} eise 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) {
console.log("You are older than 20 years ");
}
}
main();
e. function main()
{
var total;
total = Number(prompt("Enter your total "));
if (total > 100){
console.log("You have scored over 100% ");
}
}
main();
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.