Skip to content

Commit ce43bd9

Browse files
committed
Added increment/decrement functions to .js - NOT g2g (calculating backwards)
1 parent 4929425 commit ce43bd9

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

Project3_math_operators/JS/main.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ function allAtOnce() {
5353
// Step 88:
5454
function negation() {
5555
var operand = Math.floor(Math.random() * 101) + 1; // Random integer between 1 & 100
56-
document.getElementById("negation").innerHTML = `The value: ${operand}... `; // >>> DOM is updated with the chosen random number
56+
document.getElementById("negation").innerHTML = `The value: ${operand}... <br>`; // >>> DOM is updated with the chosen random number
5757
document.getElementById("Negation").innerHTML = `...becomes <strong>${-operand}<strong>!`;
5858
}
59+
// Step 90
60+
function increment() {
61+
var randNum = Math.floor(Math.random() * 101) + 1; // Random integer between 1 & 100
62+
var newRandNum = randNum--; // "++" DECREASES randNum by 1, but "--" is INCREASING it - weird
63+
document.getElementById(
64+
"Increment",
65+
).innerHTML = `The value ${randNum} was <em>incremented</em> (by one) to ${newRandNum}.`;
66+
}
67+
function decrement() {
68+
var randNumb = Math.floor(Math.random() * 101) + 1; // Random integer between 1 & 100
69+
var newRandNumb = randNumb++; // Same as above; "--" INCREASES randNumb by 1, while "++" DECREASES it
70+
document.getElementById(
71+
"Decrement",
72+
).innerHTML = `The value ${randNumb} has been <em>decremented</em> (by one) to ${newRandNumb}.`;
73+
}

Project3_math_operators/index.html

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
<title>Math Operators Assignment - Steps 78 - 94</title>
99
</head>
1010
<body>
11-
<p onClick="randomNum()">Click this line of text (repeatedly) to display random numbers, below...</p>
11+
<p onClick="randomNum()"><u>Step 78</u>: Click this line of text (repeatedly) to display random numbers, below...</p>
1212
<p id="Math"></p>
1313
<hr />
14-
<p onClick="subtraction()">Click here for examples of subtraction...</p>
14+
<p onClick="subtraction()"><u>Step 80</u>: Click here for examples of subtraction...</p>
1515
<p id="Subtraction"></p>
1616
<hr />
17-
<p onClick="multiplication()">For multiplication, please click here for examples...</p>
17+
<p onClick="multiplication()"><u>Step 82</u>: For multiplication, please click here for examples...</p>
1818
<p id="Multiplication"></p>
1919
<hr />
20-
<p onClick="division()">And click here for examples of division, displaying below...</p>
20+
<p onClick="division()"><u>Step 82 (cont'd)</u>: And click here for examples of division, displaying below...</p>
2121
<p id="Division"></p>
2222
<hr />
23-
<p onClick="allAtOnce()">Clicking this line begins a JavaScript calculation involving multiple math operators;<br>
23+
<p onClick="allAtOnce()"><u>Steps 84 & 86</u>: Clicking this line begins a JavaScript calculation involving multiple math operators;<br>
2424
<ol>
2525
<li>A random number is chosen: <p id="RandNumb"></p>.</li>
2626
<ul>
@@ -32,11 +32,16 @@
3232
<li>Keep repeating with the result:<p id="Results"></p></li>
3333
</ol>
3434
<br>
35-
...which will eventually equal "1"!<br><br>This math gem works regardless of <em>WHICH</em> number you start with!</p>
35+
...which will eventually equal "1"!<br><br>(This math gem works regardless of <em>WHICH</em> number you start with!)</p>
3636
<p id="Multiples"></p>
3737
<hr>
38-
<p onClick=negation()>Click here for an example of the Negation (-) Operator, which returns the opposite (or negative) of an operand:</p>
39-
<p id="negation"><br><p id="Negation"></p>
40-
38+
<p onClick=negation()><u>Step 88</u>: Click here for an example of the Negation (-) Operator, which returns the opposite (or negative) of an operand:</p>
39+
<p id="negation"><p id="Negation"></p>
40+
<hr>
41+
<p onClick="increment()"><u>Step 90</u>: Here's an example of the Increment (++) Operator, increasing a value by +1 (click this line of text):</p>
42+
<p id="Increment"></p>
43+
<hr>
44+
<p onClick="decrement()"><u>Step 90 (cont'd)</u>: ... while this is an example of the Decrement (--) Operator, decreasing a value by -1 (yes, click here):</p>
45+
<p id="Decrement"></p>
4146
</body>
4247
</html>

0 commit comments

Comments
 (0)