What I want to achieve is to stack values that I clicked from a set of numbers. Get the previous storage values, add the new value into storage and then display the new storage values.
DOM storage like sessionStorage and localStorage migh not the right thing to use in this case though you can try it if it works in your technique.
here's the set of numbers to click:
1 2 3 4 5 6 7 8 9
example expected result: (any number you click will stack like these in console)
1
1 5
1 5 2
1 5 2 9
Here's my code:
function logger(input){
//create array container/storage
var storage = [];
//get previous storage values
var previousInput = storage;
//get new input value
var newInput = input;
//add new input value to storage
var newStorageTotal = storage.push(newInput);
//display all values of storage
console.log(storage);
}
my code displays the numbers that I clicked and but it did not store the values in the storage.
Edit: It works now. here's the updated code for everyone.
//create array container/storage
var storage = [];
function logger(input){
//get previous storage values
var previousInput = storage;
//get new input value
var newInput = input;
//add new input value to storage
var newStorageTotal = storage.push(newInput);
//display all values of storage
console.log(storage);
}