SHOW:
|
|
- or go back to the newest paste.
1 | /* I am getting "TypeError: historyObject is undefined" at the line | |
2 | "currentNum = historyObject.lastNum;" | |
3 | Any help would be appreciated */ | |
4 | ||
5 | let currentNum = 0; | |
6 | let storedNum = 0; | |
7 | ||
8 | let history = []; | |
9 | let historyIndex = null; | |
10 | ||
11 | function addHistory() { | |
12 | let historyObject = {lastNum: currentNum, | |
13 | value: storedNum}; | |
14 | history.unshift(historyObject); | |
15 | historyIndex = null; | |
16 | ||
17 | function historyBack() { | |
18 | if (historyIndex === history.length - 1) { | |
19 | return; | |
20 | } | |
21 | if (historyIndex === null) { | |
22 | historyIndex = 0; | |
23 | } else { | |
24 | historyIndex++; | |
25 | } | |
26 | setHistoryValues(); | |
27 | } | |
28 | ||
29 | function setHistoryValues() { | |
30 | let historyObject = history[historyIndex]; | |
31 | currentNum = historyObject.lastNum; | |
32 | storedNum = historyObject.value; | |
33 | } |