+ 1
Can tell me hiw does it work??
function del(){ var num = document.getElementById("input").value, str = ""; var arr = num.split(""); for(var i=0; i<arr.length-1; i++) { str += arr[i]; } document.getElementById("input").value = str; } and plz give an example with " for"
12 odpowiedzi
+ 1
i is a variable. each run of the for loop, i is whatever number the loop is currently on. so the first time the loop runs, i=0 .. the second time the loop runs, i=1, and so on until i meets the condition that tells it to stop. in this case, it runs as long as i<arr.length
+ 1
check the code again, I added more to it
+ 1
Thanks
+ 1
you loop and
str= arr[i]
makes str whatever the new loop says. what you want instead is
str= str+arr[i]
This way it adds the new piece to str instead of making str the new thing
0
When it add's a one to i so what does i do??
0
Can you make it with web plz
0
Thanks
0
Ok underestood
0
Thank you so much
0
Ok
0
I tried my code it delet's s.th just I don't underestand in that code Wrote's "i++" but it delet's one character