In: Computer Science
JAVA script!
You will write a program that will input the nationalities of your favorite types of food, examples, and prices of some of your favorite food. You will save a type of food, two examples of that type of food, the price of each of those two examples, and a total price of both together. You must input your own types, examples, and prices, but check a sample run below. You must use the concepts and statements that we have covered so far this semester. Use a loop that loops two times using a counter. Inside the loop, first ask the user to input the nationality of their favorite foods (ex. German, Italian, etc.). The user will now input an example of that type of food and the cost of that food. The user will now input another example of that type of food and the cost of that food. Add the two costs to a total amount variable. Now output the nationality of the type of food and the total amount of the two types of food rounded to two decimal places. Then, ask the user if they would like to list their choices, by answering either y/n or 1/2. If they say y or 1 for yes, print the two examples of that type of food. Hint: When running your program, keep track of the enters in the memory buffer. Whenever an input is skipped over, clear the enter from the input memory buffer. Whenever the program wants an extra input, do not clear the input memory buffer.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>My favorite Food</title>
<link rel="stylesheet" href="">
</head>
<body>
<div class="container">
<p id="nation"></p>
<p id="food"></p>
<p id="totalprice"></p>
</div>
</body>
<script type="text/javascript">
var fvrfood = [];
for (var i=0;i<2;i++){
var nationIN = prompt("Please enter food nationality");
var food = prompt("Please enter your favorite food ", "food name");
var price = prompt("Please enter food price","food price");
fvrfood.push((nationIN),(food),Number(price));
}
var choice = prompt("Are you want print your data enter y/n")
if(choice == "y"){
var print = fvrfood.values();
for (var elements of print) {
console.log(elements);
}
}
else{
console.log("end");
}
</script>
</html>