Program Requirements This program should add numbers 1 through 9 one a time, via a button click, display the result, and allow the user to Clear the total to zero. Your Starter Codeworks for numbers 1 through 3.  Give it a try, push the buttons, to see what it does. Extending Structured Programs is Easy In this assignment, you use existing code to: identify the patterns in a program modify the patterns in order to extend the functionality of the program Your Task for this Assignment Requirements: Extend this program to create the 6 more HTML buttons and 6 more Javascript functions.   Software Development Best Practice: Incremental Development Do not program all your code at once like you were editing some essay.  Making a big mess and then trying to patch it up all one once... is a nightmare. Add one button and its function Test it Repeat with the next button Pattern One: HTML Button Add your HTML code where the highlighted area is in the image below.  Copy an existing button, and modify the function name and the button text.  I have started your button 4 and put it in a <--!  html comment --> Starter Code: <!DOCTYPE html><html><head><style>* { font-family: arial }</style></head><body><h2 style="background-color:lightyellow">Addition Calculator</hr><div style="background-color:lightblue"><button onclick="funcOne()">+1</button><button onclick="funcTwo()">+2</button><button onclick="funcThree()">+3</button><!-- ASSIGNMENT Task 1.: Copy the button code above --><!--- For example:<button onclick="funcFour()">+4</button>--> <button onclick="clearTotal()">Clear</button></div><p id="message"></p> <script>// javascript code begin// These two lines of code happen as soon as the program runs:var total=0; // start with zero for totalshowTotal(); // display this initial total // These functions only trigger when a button is pressed:function funcOne(){// Algorithm: 1) add 1 to total, 2) display to Usertotal = total + 1;showTotal();}function funcTwo(){// Algorithm: 1) add 2 to total, 2) display to Usertotal = total + 2;showTotal();}function funcThree(){ // Algorithm: 1) add 3 to total, 2) display to Usertotal = total + 3;showTotal();}// ASSIGNMENT Task 2: create a function for each new button// Copy and modify the code above.// START ADDING YOUR CODE HERE:/// for example:/* function funcFour(){ // Algorithm: 1) add 3 to total, 2) display to Usertotal = total + 4;showTotal();} */ // END OF ADDING YOUR CODEfunction clearTotal(){ // Algorithm: 1) set total to zero, 2) display to Usertotal=0;showTotal();}//--------------------------------------------------------------// A utility function simply because the code below is correct but gross to look at.// Everywhere you see showTotal() above, will be automatically replaced with this code.function showTotal(){// Algorithm: use this scary code to change textdocument.getElementById("message").innerHTML=total;} // javascript code end</script></body>

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.3: Interactive While Loops
Problem 6E: (Conversion) a. Write a C++ program to convert meters to feet. The program should request the...
icon
Related questions
Question

Program Requirements

This program should add numbers 1 through 9 one a time, via a button click, display the result, and allow the user to Clear the total to zero.

Your Starter Codeworks for numbers 1 through 3.  Give it a try, push the buttons, to see what it does.

Extending Structured Programs is Easy

In this assignment, you use existing code to:

  • identify the patterns in a program
  • modify the patterns in order to extend the functionality of the program

Your Task for this Assignment

Requirements: Extend this program to create the 6 more HTML buttons and 6 more Javascript functions.

 

Software Development Best Practice: Incremental Development

Do not program all your code at once like you were editing some essay.  Making a big mess and then trying to patch it up all one once... is a nightmare.

  1. Add one button and its function
  2. Test it
  3. Repeat with the next button

Pattern One: HTML Button

Add your HTML code where the highlighted area is in the image below.  Copy an existing button, and modify the function name and the button text.  I have started your button 4 and put it in a <--!  html comment -->

Starter Code:

<!DOCTYPE html>
<html>
<head><style>
* { font-family: arial }
</style></head>
<body>
<h2 style="background-color:lightyellow">Addition Calculator</hr>
<div style="background-color:lightblue">
<button onclick="funcOne()">+1</button>
<button onclick="funcTwo()">+2</button>
<button onclick="funcThree()">+3</button>
<!-- ASSIGNMENT Task 1.: Copy the button code above -->
<!--- For example:
<button onclick="funcFour()">+4</button>
-->

<button onclick="clearTotal()">Clear</button>
</div>
<p id="message"></p>

<script>
// javascript code begin
// These two lines of code happen as soon as the program runs:
var total=0; // start with zero for total
showTotal(); // display this initial total

// These functions only trigger when a button is pressed:
function funcOne(){
// Algorithm: 1) add 1 to total, 2) display to User
total = total + 1;
showTotal();
}
function funcTwo(){
// Algorithm: 1) add 2 to total, 2) display to User
total = total + 2;
showTotal();
}
function funcThree(){
// Algorithm: 1) add 3 to total, 2) display to User
total = total + 3;
showTotal();
}
// ASSIGNMENT Task 2: create a function for each new button
// Copy and modify the code above.
// START ADDING YOUR CODE HERE:
/// for example:
/* function funcFour(){
// Algorithm: 1) add 3 to total, 2) display to User
total = total + 4;
showTotal();
} */


// END OF ADDING YOUR CODE
function clearTotal(){
// Algorithm: 1) set total to zero, 2) display to User
total=0;
showTotal();
}
//--------------------------------------------------------------
// A utility function simply because the code below is correct but gross to look at.
// Everywhere you see showTotal() above, will be automatically replaced with this code.
function showTotal(){// Algorithm: use this scary code to change text
document.getElementById("message").innerHTML=total;
}

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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Mathematical functions
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr