Can anyone help me with this JavaScript Code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can anyone help me with this JavaScript Code?

//program to push a value to an array //I ran this code in Chrome inspect/sources. // each time we hit run ,the length of array should be increased. //After the length increases, it should display the values of array //So each run increases the value of an Array by 1. //But it is not working //code is below: var output= [];//arrray var count=1; function increase() { output.push(count); count++; console.log(output); } increase();

16th May 2021, 9:29 AM
Coding San
Coding San - avatar
7 Answers
+ 3
You can see how your code works this way too: https://code.sololearn.com/WrUrOWZT4gtQ/?ref=app
16th May 2021, 12:12 PM
JaScript
JaScript - avatar
+ 1
Yeah that's what I am saying If you wanna save the data you have to use some kind of data base Or file handling
16th May 2021, 10:27 AM
YUGRAJ
+ 1
It appears that when the run button is pressed that window.document is reset but window is not(sololearn website only). That is what it appears to be but I'm not sure. https://code.sololearn.com/WA3A116a14A1
16th May 2021, 5:09 PM
ODLNT
ODLNT - avatar
0
Hi! you call the function with the last line, but you don't pass it any parameter in parentheses
16th May 2021, 9:32 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Each time you run code the array will be reinisitialised with no element in it i guess so each time you run you get only one element
16th May 2021, 9:38 AM
YUGRAJ
0
the way the task is set is difficult to implement in the code pad here, because we do not have the ability to save the changed data. every time we press run everything will reset to the beginning
16th May 2021, 10:26 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
most likely now browsers can save some information locally, but I have not studied these methods. therefore, it is better to write such a program and test it in the browser or use the data transfer as a client-server
16th May 2021, 10:32 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar