Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The snippets of JavaScript below contain syntax errors and/or logic errors. Iden

ID: 3687569 • 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 daysOfWeek = [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday];

   

}

main();

b. function main()

{

    var highScore;

    var lowScore;

   

    var numExams = 5;

    var examArray = [];

   

    for (ctr = 0; ctr< numExams; ctr++)

    {

        examArray[ctr] = Number(prompt("Enter the score for exam " + ctr));

    }

   

    highScore = examArray[0];

    lowScore = examArray[0];

   

    for (ctr = 0; ctr< numExams; ctr++)

    {

        if (examArray[ctr] > highScore)

        {

            highScore = examArray[ctr];

        }

        else

        {

            lowScore = examArray[ctr];

        }

    }

    console.log("High score is " + highScore);

    console.log("low score is " + lowScore);

}

main();

c. function main()

{

                var itemArray = [];

                var arraySize = 5;

for (var ctr = 0; ctr < arraySize; ctr++)

{

                itemArray[0] = Number(prompt("Enter the price of item# " + ctr));         

}

}

main();

d. function main()

{

                var numArray = [];

for (var ctr = 0; ctr < 10; ctr++)

{

                                numArray(ctr) = ctr;

}

}

main();

e. function main()

{

var numStus = Number(prompt("Enter the number of students"));

                var stuArray = new Array(numStus);

for (ctr = 0; ctr <= numStus; ctr++)

{

                stuArray[ctr] = prompt("Enter the name of student # " + ctr);

}

}

main();

Explanation / Answer

Please find belo the error free java scripts .

Question a:

function main()
{

var daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

}

Question b:

function main()

{

    var highScore;

    var lowScore;

   

    var numExams = 5;

    var examArray = [];

   

    for (ctr = 0; ctr< numExams; ctr++)

    {

        examArray[ctr] = Number(prompt("Enter the score for exam " + ctr));

    }

   

    highScore = examArray[0];

    lowScore = examArray[0];

   

    for (ctr = 0; ctr< numExams; ctr++)

    {

        if (examArray[ctr] > highScore)

        {

            highScore = examArray[ctr];

        }

        else

        {

            lowScore = examArray[ctr];

        }

    }

    console.log("High score is " + highScore);

    console.log("low score is " + lowScore);

}

Question C:

function main()
{
var itemArray = [];
var arraySize = 5;

for (var ctr = 0; ctr < arraySize; ctr++)
{
itemArray[ctr] = Number(prompt("Enter the price of item# " + ctr));   
}
}

Question D:

function main()

{

                var numArray = [];

for (var ctr = 0; ctr < 10; ctr++)

{

                                numArray[ctr] = ctr;

}

}

Question E:

function main()

{

var numStus = Number(prompt("Enter the number of students"));

                var stuArray = new Array(numStus);

for (ctr = 0; ctr <= numStus; ctr++)

{

                stuArray[ctr] = prompt("Enter the name of student # " + ctr);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote