Purchase Appple Purchase Orange

Microsoft Windows 10 Comprehensive 2019
1st Edition
ISBN:9780357392607
Author:FREUND
Publisher:FREUND
Chapter8: Mastering Digital Media
Section: Chapter Questions
Problem 1EYK
icon
Related questions
Question

Instructions

This assignment uses the logic from the recent quiz and assignment.  You can see some of that code in there.
What is different?  The sequence of operations, spending and finding money, is totally controllable with buttons.
This makes the program very flexible.

Update the Code below with the following:

  1. Add 2 new event functions: buyTortilla() and addFoundMoney().
  2. Add 2 new buttons that trigger buyTortilla() and addFoundMoney().

STARTER CODE

<!DOCTYPE html>
<html><head><style>p {font-family: arial; font-size: 20px;} </style></head>
<body>

<button onclick='buyApple()'>Purchase Appple</button>
<button onclick='buyOrange()'>Purchase Orange</button>

<!-- This marks space for a paragraph that we can update during the program -->
<p id="balance"></p>

<script>
// javascript code begin
// Step 1. initialize variables:
change=100 // starting balance
apple=10 // price of 1 apple
orange=20 // price of 1 orange
tortilla=30 // price of 1 tortilla
foundMoney=25 // pretend found $25
// initialize the user-interface when this page loads:
document.getElementById("balance").innerHTML = "$"+change;
// Step 2. define event functions for each button
function buyApple(){
change -= apple;
document.getElementById("balance").innerHTML = "$"+change;
}
function buyOrange(){
change -= orange;
document.getElementById("balance").innerHTML = "$"+change;
}
// Make 2 more functions here, to match the 2 new buttons:

// javascript code end
</script>
</body>
</html>

 

 

<! DOCTYPE html>
<html><head><style>p {font-family: arial; font-size: 20px;} </style></head>
<body>
<button onclick='buyApple()'>Purchase Appple</button>
<button onclick='buyorange ()'>Purchase Orange</button>
<!-- This marks space for a paragraph that we can update during the program
<p id="balance"></p>
-->
<script>
// javascript code begin
// Step 1. initialize variables:
change=100 // starting balance
apple=10
orange=20 // price of 1 orange
tortilla=30 // price of 1 tortilla
foundMoney=25 || pretend found $25
T| initialize the user-interface when this page loads:
document.getElementById ("balance").innerHTML = "$"+change;
// Step 2. define event functions for each button
function buyApple(){
change
document.getElementById ("balance").innerHTML
// price of 1 apple
apple;
= "$"+change;
function buyorange (){
change -= orange;
document.getElementById ("balance").innerHTML
"$"+change;
// Make 2 more functions here, to match the 2 new buttons:
// javascript code end
</script>
</body>
</html>
Transcribed Image Text:<! DOCTYPE html> <html><head><style>p {font-family: arial; font-size: 20px;} </style></head> <body> <button onclick='buyApple()'>Purchase Appple</button> <button onclick='buyorange ()'>Purchase Orange</button> <!-- This marks space for a paragraph that we can update during the program <p id="balance"></p> --> <script> // javascript code begin // Step 1. initialize variables: change=100 // starting balance apple=10 orange=20 // price of 1 orange tortilla=30 // price of 1 tortilla foundMoney=25 || pretend found $25 T| initialize the user-interface when this page loads: document.getElementById ("balance").innerHTML = "$"+change; // Step 2. define event functions for each button function buyApple(){ change document.getElementById ("balance").innerHTML // price of 1 apple apple; = "$"+change; function buyorange (){ change -= orange; document.getElementById ("balance").innerHTML "$"+change; // Make 2 more functions here, to match the 2 new buttons: // javascript code end </script> </body> </html>
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Microsoft Windows 10 Comprehensive 2019
Microsoft Windows 10 Comprehensive 2019
Computer Science
ISBN:
9780357392607
Author:
FREUND
Publisher:
Cengage
Enhanced Discovering Computers 2017 (Shelly Cashm…
Enhanced Discovering Computers 2017 (Shelly Cashm…
Computer Science
ISBN:
9781305657458
Author:
Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Publisher:
Cengage Learning