Question 1- I & II
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<script type="text/javascript">
var nescafe = prompt("Nescafe?","Enter Value");
var apple = prompt("Apple?","Enter Value");
var cocomilk = prompt("Coco Milk?","Enter Value");
var maggiemee = prompt("Maggie Mee?","Enter Value");
var nescafe_price = parseInt(nescafe)*10.50;
var apple_price = parseInt(apple)*1.20;
var cocomilk_price = parseInt(cocomilk)*1.50;
var maggiemee_price = parseInt(maggiemee)*3.50;
var subtotal = nescafe_price + apple_price + cocomilk_price + maggiemee_price;
/* Display the receipt */
document.write("<h2> ABC Shop Enterprise </h2>");
document.write("<br>")
document.write("<table>");
document.write("<tr><th width=130px> Item</th>");
document.write("<th width=120px> Price </th>");
document.write("<th width=110px> Total </th></tr>");
document.write("<tr><td>Nescafe @ " + nescafe + "</td>");
document.write("<td>RM10.50</td>");
document.write("<td>RM " + nescafe_price.toFixed(2) + "</td></tr>");
document.write("<tr><td>Apple @ " + apple + "</td>");
document.write("<td>RM1.20</td>");
document.write("<td>RM " + apple_price.toFixed(2) + "</td></tr>");
document.write("<tr><td>Coco Milk @ " + cocomilk + "</td>");
document.write("<td>RM1.50</td>");
document.write("<td>RM " + cocomilk_price.toFixed(2) + "</td></tr>");
document.write("<tr><td>Maggie Mee @ " + apple + "</td>");
document.write("<td>RM3.50</td>");
document.write("<td>RM " + maggiemee_price.toFixed(2) + "</td></tr>");
document.write("<tr><td class=white>" + "</td>");
document.write("<td class=yellow>SubTotal" + "</td>");
document.write("<td class=yellow>RM" + subtotal.toFixed(2) + "</td></tr>");
document.write("<tr><td class=white>" + "</td>");
document.write("<td class=yellow>GST" + "</td>");
document.write("<td class=yellow>RM" + 0.06*subtotal.toFixed(2) + "</td></tr>");
document.write("<tr><td class=white>" + "</td>");
document.write("<td class=black >Grand Total" + "</td>");
document.write("<td class=black >RM" + (subtotal+0.06*subtotal).toFixed(2) + "</td></tr>");
document.write("</table>");
</script>
</body>
</html>
mystyle.css
body{font-family: Arial;}
table.design{
font-size:12px; }
th{
background-color: #FFC42B; padding: 5px; font-weight: bold; }
td.black{
background-color: #FFC42B; padding: 5px; font-weight: bold;
color : black; }
td.yellow{
background-color: yellow; padding: 5px;
font-weight: bold; color : red; }
td.white{
background-color: white; padding: 5px;
font-weight: bold; color : red; }
td{
background-color: #FFF7B8; color : #666666; padding: 5px;}
Question 1- III
<html>
<body>
<script type="text/javascript">
var num1 = prompt("Enter interger");
var num2 = prompt("Enter interger");
var operator = prompt("Enter an operator");
if (operator == "+") {
var result = parseInt(num1)+ parseInt(num2);
document.write(num1 + " + " + num2 + " = " + result + "<br>");
}
else if (operator == "*") {
var result = parseInt(num1)*parseInt(num2);
document.write(num1 + " * " + num2 + " = " + result + "<br>");
}
else if (operator == "/") {
if (num2 == 0)
alert(num1 + " / " + num2 + " = " + "Cannot divide by Zero");
else
var result = parseInt(num1)/parseInt(num2);
document.write( result + "<br>");
}
else{
alert("Invalid operator! Refresh and try again!");
}
</script>
</body>
</html>
No comments:
Post a Comment