Lab15
This commit is contained in:
		
							
								
								
									
										48
									
								
								Chapter ZIPs/JavaScript/ch7/ex_7_7.html
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										48
									
								
								Chapter ZIPs/JavaScript/ch7/ex_7_7.html
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,48 @@
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
<title>Example 7.7</title>
 | 
			
		||||
<script>
 | 
			
		||||
function getDiscount()
 | 
			
		||||
{
 | 
			
		||||
	var item = " ";
 | 
			
		||||
	item = prompt("What is the item you want to buy?");
 | 
			
		||||
	cost = parseFloat(prompt("How much does this item cost?"));
 | 
			
		||||
	checkNum(cost);
 | 
			
		||||
	if (cost < 50)
 | 
			
		||||
	{
 | 
			
		||||
		rate = .10;
 | 
			
		||||
		salePrice = cost * (1 - rate);
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
		if (cost < 100)
 | 
			
		||||
		{
 | 
			
		||||
			rate = .15;
 | 
			
		||||
			salePrice = cost * (1 - rate);
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			rate = .20; 
 | 
			
		||||
			salePrice = cost * (1 - rate);
 | 
			
		||||
		}
 | 
			
		||||
	document.getElementById('item').innerHTML = item;
 | 
			
		||||
	document.getElementById('orig_price').innerHTML = ("$ " + cost.toFixed(2));
 | 
			
		||||
	document.getElementById('discount').innerHTML = ((rate * 100) + "%");
 | 
			
		||||
	document.getElementById('result').innerHTML = ("$ " + salePrice.toFixed(2));	
 | 
			
		||||
}
 | 
			
		||||
	function checkNum(num)
 | 
			
		||||
	{
 | 
			
		||||
		if (num < 0)
 | 
			
		||||
			alert("Invalid cost entered");
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
</script>
 | 
			
		||||
</head>
 | 
			
		||||
<body><table align="center" width = "70%"><tr><td><br />
 | 
			
		||||
<input type ="button" onclick="getDiscount()" value = "How much will you save? Find out now"></button><br />
 | 
			
		||||
<h3>You plan to purchase: <span id = "item"> </span></h3>
 | 
			
		||||
<h3>The original cost is: <span id = "orig_price"> </span></h3>
 | 
			
		||||
<h3>The discount rate is: <span id = "discount"> </span></h3>
 | 
			
		||||
<h3>You pay: <span id = "result"> </span></h3>
 | 
			
		||||
</td></tr></table>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
		Reference in New Issue
	
	Block a user