In: Computer Science
Put your name on the first line in camelCase. Write a JavaScript function to calculate the revenue for blocks sales. Input the number of wooden blocks, the number of plastic blocks and the number of rubber blocks. Wooden blocks are $5. Plastic blocks are $2 and rubber blocks are $4. Calculate the cost for each type of block. Calculate the total cost. Display the four outputs on the page. Label the inputs and the output on your page. Change the title to "Study Hard for the Test!!".
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body onload="revenue()">
<center id="title"></center>
<p id="input"></p>
<p id="output"></p>
</body>
<script type="text/javascript">
function revenue(){
var plastic =
parseInt(prompt('Enter number of Plastic blocks: '));//entering the
platic boxes
var wooden = parseInt(prompt('Enter
number of Wooden blocks: '));//entering the wooden boxes
var rubber = parseInt(prompt('Enter
number of Rubber blocks: '));//entering the rubber boxes
var total =
plastic*2+wooden*5+rubber*4;// calculating the total
document.getElementById('input').innerHTML =
"<b>Input</b><br>Number of Plastic blocks:
"+plastic+"<br>Number of Wooden blocks: "+wooden+
"<br>Number of Rubber blocks:
"+rubber;//step to display the input
document.getElementById('output').innerHTML =
"<b>Output</b><br>Cost of Plastic blocks:
$"+(plastic*2)+
"<br>Cost of Wooden blocks:
$"+(wooden*5)+"<br>Cost of Rubber blocks:
$"+(rubber*4)+"<br>Total cost: $"+(total);//step to display
the output
document.getElementById('title').innerHTML = "Study Hard for the
Test";//step to display the title
}
</script>
</html>