Create a Web page that prompts the user for information, stores it in an array,
ID: 3549891 • Letter: C
Question
Create a Web page that prompts the user for information, stores it in an array, performs a math operation, and writes the information out on the page. Requirements: Create a web page named lab2.html. You can format the page any way that you like. Give the page a title and heading. In the body of the web page, after the heading, create an array that includes 3 trivia questions. Create another array with 5 quotes of the day. Prompt the user to enter a number. Divide the number by 5 and get the remainder. Use the remainder as the array index and write that quote to the page. Prompt the user to enter a trivia question and store it as the last item in the array. Delete the first item from the array and store it in a variable. Prompt the user to enter a second trivia question and store it as the first item in the array. Write out all questions from the array on the page as a trivia quiz. Write out the deleted question stored in the variable as the bonus question. Add comments to your code.Explanation / Answer
<!DOCTYPE html>
<html>
<head>
<title>Lab2</title>
</head>
<body>
<h1>Lab 2</h1>
<p id="quote"></p>
<script type="text/javascript">
//trivia array
var trivia=new Array("what is meaning of life?","When was UNO founded","What is full form of BMW");
//quotes array
var quotes=new Array("Don't cry because it's over, smile because it happened.","You only live once, but if you do it right, once is enough.","Insanity is doing the same thing, over and over again, but expecting different results","Time flies over us, but leaves it shadow behind.","The first magic of love is our ignorance that it can ever end.");
//prompts user for a number
var number = prompt("Please enter a number");
//outputs quote by calculating remainder
document.getElementById("quote").innerHTML=quotes[number%5];
//prompts user for a trivia
var newQuote = prompt("Please enter a triva");
//adds to end of array
trivia.push(newQuote);
//removes first element of array and save to a avariable
var bonus = trivia.shift();
//prompts user for a trivia
newQuote = prompt("Please enter another trivia");
//adds trivia at the beginning of array
trivia.unshift(newQuote);
//outputs the trivia questions as a list
document.write("<ul>");
for (index = 0; index < trivia.length; index++) {
document.write("<li>"+trivia[index]+"</li>");
}
document.write("<li>Bonus trivia: "+bonus+"</li>");
document.write("</ul>");
</script>
</body>
</html>