Javascript/HTML. Would someone be able to help me with this program. It is suppo
ID: 3771336 • Letter: J
Question
Javascript/HTML. Would someone be able to help me with this program. It is suppose to allow the user to enter the number of dumplings Po eats every month and the user should be able to enter as many data sets as desired using a do while loop. It also has to calculate the total number of dumplings po ate. An example input would be: Enter the month: Jan, How many dumplings did po eat? 600, Enter another month or enter 'done' when finished: Feb, How many dumplings did po eat? 700, enter another month or enter 'done' when finished: done. An example output would be:
Po's Dumpling Log:
Month Number of Dumplings
JAN 600 dumplings
FEB 700 dumplings
Any help would be greatly appreciated, thank you in advance
<!DOCTYPE html>
<html lang="en">
<head> <!-- open of head -->
<meta charset="utf-8">
<title> Mikayla's Kung Fu Panda Po Dumpling Log </title>
<link rel="shortcut icon" href="me.jpg">
<link rel="stylesheet" href="style.css"> <!-- connects to style sheet -->
</head>
<body> <!-- beginning of the body section -->
<header>
<h1> Mikayla's Kung Fu Panda<br>Po Dumpling Log </h1>
</header>
<script type="text/javascript">
function ()
var amountOfDumplings;
var totalDumplings;
var month;
{
do
{
}
while
{
}
}
</script>
<h2>
Click on the buttons below to enter the number of <br> dumplings Po eats every month.
</h2>
<div id="content">
<p> <button type="button">Mikayla's Po Dumpling log</button><br><br>
<p> Po's Dumpling Log: <span id = "dumplings" > </span> <br> </p>
<p> <span id = "message2" > </span> <br> </p>
</div>
</body>
</html>
Explanation / Answer
Code:
<!DOCTYPE html>
<html lang="en">
<head> <!-- open of head -->
<meta charset="utf-8">
<title> Mikayla's Kung Fu Panda Po Dumpling Log </title>
<link rel="shortcut icon" href="me.jpg">
<link rel="stylesheet" href="style.css"> <!-- connects to style sheet -->
<header>
<h1> Mikayla's Kung Fu Panda<br>Po Dumpling Log </h1>
</header>
<script type="text/javascript">
function amount()
{
var amountOfDumplings;
var totalDumplings=0;
var month;
var str = "";
//Reading Month for the first time
month = prompt("Enter the Month: ");
do
{
//Reading number of dumplings
amountOfDumplings = prompt("How Many Dumplings did Po eat");
//Constructing output string
str = str + "<br>" + month + " " + amountOfDumplings + " " + "dumplings" + "<br>";
//Calculating total dumplings
totalDumplings = parseInt(totalDumplings) + parseInt(amountOfDumplings);
//Reading Month Again
month = prompt("Enter the Month: (or) Enter 'done' when finished");
}while(month != "done"); //Stop when user enters 'done'
//Add the constructed strings to output
document.getElementById('dumplings').innerHTML = str;
document.getElementById('message2').innerHTML = totalDumplings + " Dumplings";
}
</script>
</head>
<body> <!-- beginning of the body section -->
<h2>
Click on the buttons below to enter the number of <br> dumplings Po eats every month.
</h2>
<div id="content">
<p> <button type="button">Mikayla's Po Dumpling log</button><br><br>
<p> Po's Dumpling Log: <br><br> Month Number Of Dumplings <span id = "dumplings"> </span> <br> </p>
<p><br>Total Number of Dumplings Po ate : <span id = "message2" > </span> <br> </p>
</div>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.