Skip to content

Commit 8ed8a18

Browse files
committed
feat(JS) refactor code by creating createHistoryList()
1 parent e072e77 commit 8ed8a18

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

index.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,21 +218,11 @@ function userClicksOnEqualButton(button) {
218218
// divideByZero(screen, result);
219219
data = [];
220220
data.push(result);
221-
historyEntries.forEach((entry, index) => {
222-
console.log(entry);
223-
history.push(entry);
224-
if(history.length > 3) {
225-
history.pop()
226-
}
227-
console.log(history);
228-
historyElement.innerHTML += `<li> ${entry.join(" ")}</li>`
229-
if(historyElement.childElementCount > 10) {
230-
console.log("hi")
231-
historyElement.firstElementChild.remove()
232-
233-
}
234-
235-
});
221+
222+
createHistoryList(historyEntries, historyElement, history)
223+
224+
225+
236226

237227

238228

@@ -271,4 +261,20 @@ function displayResult(array, outcome) {
271261
array = [];
272262
array.push(outcome);
273263
}
264+
265+
266+
function createHistoryList(array, element, history) {
267+
array.forEach((entry, index) => {
268+
269+
history.push(entry);
270+
271+
element.innerHTML += `<li> ${entry.join(" ")}</li>`
272+
if(element.childElementCount > 10) {
273+
console.log("hi")
274+
element.firstElementChild.remove()
275+
}
276+
});
277+
}
278+
279+
274280
// functions creations ends

0 commit comments

Comments
 (0)