I\'m having trouble with this one. Here\'s what I have to do: I\'m creating a pa
ID: 3547630 • Letter: I
Question
I'm having trouble with this one. Here's what I have to do:
I'm creating a page that allows the user to buy items/toys.
The page I'm creating should include at least two parallel arrays.
One of these holds the listing (names) of the items,
The other holds their corresponding prices.
The page retrieves values from these parallel arrays, displaying their names and prices.
The user should be prompted to select an item and quanitity of that item.
The page will display the total cost for that quantity, as well as what I've stated above.
Here's what I have so far:
<script type="text/javascript">
var item = newArray("itemOne","itemTwo","itemThree","itemFour");
var price = secondArray(6,5,4,3);
function getStuff()
{
var itemNumber=prompt("Enter the number that corresponds with the item you want to buy");
var itemQuantity=prompt("How many of these do you want?");
var yesOrNo=prompt("Do you want to purchase another item?")
var totalCost
if(yesOrNo=N || yesOrNo=no){
document.getElementById( 'lbl1' ).textContent = "Item: " + item ;
document.getElementById( 'lbl1' ).textContent = "Cost: $ " + cost ;
document.getElementById( 'lbl1' ).textContent = "Number Requested: " + itemQuantity ;
document.getElementById( 'lbl1' ).textContent = "Total Cost: " + totalCost;
}
</script>
</head>
<body>
<header>
</header>
<form name="form1">
<p><input type="Button" value="Begin Purchase" /></p>
<p>1.Item $6</p>
<p>2. Item Two => $5</p>
<p>3. Item Three => $4</p>
<p>4. Item Four => $3</p>
<br>
<p id="lbl1" > </p>
</form>
</body>
</html>
Explanation / Answer
<html>
<head>
<script type="text/javascript">
var item = new Array("itemOne","itemTwo","itemThree","itemFour");
var price = new Array(6,5,4,3);
var totalCost = 0;
var content = "";
function getDetails()
{
content += "Item  ";
content += "Cost ";
content += "Quantity ";
content += "Cost <br>";
do{
var itemNumber=prompt("Enter the number that corresponds with the item you want to buy");
var itemQuantity=prompt("How many of these do you want?");
var yesOrNo=prompt("Do you want to purchase another item?")
totalCost += (price[itemNumber-1] * itemQuantity);
content += item [itemNumber-1] +" ";
content += price[itemNumber-1] +" ";
content += itemQuantity +" ";
content += (price[itemNumber-1] * itemQuantity) +" <br>";
}while(yesOrNo != 'NO' && yesOrNo != 'no');
content +="<br> Total cost: " + totalCost;
document.getElementById( 'test' ).innerHTML = content;
}
</script>
</head>
<body>
<header>
</header>
<form name="form1">
<p><input type="Button" value="Begin Purchase" /></p>
<p>1.Item $6</p>
<p>2. Item Two => $5</p>
<p>3. Item Three => $4</p>
<p>4. Item Four => $3</p>
<br>
<p id="lbl1" >
<pre id="test">
</pre>
</p>
</form>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.