-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcreateNewAccumlator.js
More file actions
25 lines (18 loc) · 909 Bytes
/
createNewAccumlator.js
File metadata and controls
25 lines (18 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*Create a constructor function Accumulator(startingValue).
Object that it creates should:
Store the “current value” in the property value. The starting value is set to the argument of the constructor startingValue.
The read() method should use prompt to read a new number and add it to value.
In other words, the value property is the sum of all user-entered values with the initial value startingValue.
*/
function Accumulator(startingValue) {
//holds the startingValue to be minipulated
this.value = startingValue;
this.read = function () {
//adds the prompted amount to the value at the moment
this.value += parseFloat(prompt("what is the first value"));
};
}
let accumulator = new Accumulator(1); // initial value 1
accumulator.read(); // adds the user-entered value
accumulator.read(); // adds the user-entered value
alert(accumulator.value); // shows the sum of these values