Write a Javascript program that Allows the user to buy Po’s toys as listed on th
ID: 3818208 • Letter: W
Question
Write a Javascript program that Allows the user to buy Po’s toys as listed on the page.The page should include parallel arrays (at least two).One array (RichardItem) holds the names of the toys. (-7 points if no array)
var RichardItem = new Array ("Po action figure", "Master Shifu action figure", "Lord Shen action figure");
One array (RichardPrice) holds the corresponding prices for each toy.
var RichardPrice = new Array(7, 6, 5); (-7 points if no array)
Retrieve values from the parallel arrays, display the toys’ names/prices as shown (hint: onload). (4 points)
The user should be prompted to select a toy and a quantity. (4 points)
The page will display the total cost for that quantity of the toy chosen (by using the values from the parallel arrays). (6 points)
Webpage program should follow examples below
Initial page
OUTPUT
Richard Ricardo's Kung Fu Panda Po Toy Sale Three parallel arrays will hold an toy item's name, price, and identifier. The user will make the purchase. The program will calculate the total cost. Begin Purchase 1. Po action figure 7 2. Master Shifu action figure 6 3. Lord Shen action figure 5Explanation / Answer
<!DOCTYPE html>
<html>
<head>
<title>Initial Page</title>
</head>
<body>
<h1>Richard Ricardo's Kung Fu Panda Po Toy Sale</h1>
<h3>Three parallel arrays will hold an toy item's name, price, and identifier.</h3>
<h3>The user will make the purchase</h3>
<h3>The program will calculate the total cost</h3>
<button>Begin Purchase</button>
<h3>1. Po action figure => $7</h3>
<h3>2. Master Shifu action figure => $6</h3>
<h3>3. Lord Shen action figure => $5</h3>
<h3 id ="demo"></h3>
<script>
function myFunction() {
var RichardItem = new Array ("Po action figure", "Master Shifu action figure", "Lord Shen action figure");
var RichardPrice = new Array(7, 6, 5);
var ch = 'y'
while(ch == 'y')
{
var item = prompt("Enter the number that corresponds with the item you want to buy:");
item -= 1;
var num = prompt("How many of these do you want?");
var total = RichardPrice[item] * num;
document.getElementById("demo").innerHTML += "Item: " + RichardItem[item] + "<br> Cost: $ " + RichardPrice[item] + "<br> Number requested: " + num +"<br> Total Cost: $ " + total + "<br><br>";
ch = prompt("Do you want to purchase another item? (y/n)")
}
}
</script>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.