+ 2

My button keeps disappearing.

I am making a button that takes the different letters of the string "Hello" and displays it every time a button is clicked. My problem is that the first time my button is clicked, it disappears so I don't get to click it a second time. Each time I click it I want it to concat the letters of "Hello" together adding one letter of a time. I used a which means I probably shouldn't have used a switch function. But for now I just want feedback on how to get my button to not disappear. https://code.sololearn.com/WicKTVVOHsmi/#js

22nd Apr 2018, 5:01 PM
Babydoll Scripts
Babydoll Scripts - avatar
6 Answers
+ 10
case 0 :string.charAt(0); break; case 1:string.charAt(1); p.innerHTML = string.charAt(1); break; case 2: string.charAt(2); P.innerHTML = string.charAt(2); break; case 3:string.charAt(3); p.innerHTML = string.charAt(3); break; case 4:string.charAt(4); p.innerHTML = string.charAt(4); break;
23rd Apr 2018, 1:28 AM
Ahlin Chan
Ahlin Chan - avatar
+ 11
you are using document.write() function which removes all things you make then write on the web so you need to add paragraph to you Html <p></p> and add ID for it exmaple <p id="demo" ></p> then go to js and write var demo = document.getElementById("demo"); demo.innerHTML = string.charAt(0);
22nd Apr 2018, 5:07 PM
Ahlin Chan
Ahlin Chan - avatar
+ 10
C0d!ng K!tty still not working see you make this case 0 :string.charAt(0); break; case 1:string.charAt(1); document.write(string.charAt(1)); break; case 2: string.charAt(2); document.write(string.charAt(2)); break; case 3:string.charAt(3); document.write(string.charAt(3)); break; case 4:string.charAt(4); document.write(string.charAt(4)); break; document.write() must be p.innerHTML = ;
23rd Apr 2018, 1:25 AM
Ahlin Chan
Ahlin Chan - avatar
+ 2
@Mirage Still not working. What do I replace document.write with if that's the problem?
22nd Apr 2018, 5:24 PM
Babydoll Scripts
Babydoll Scripts - avatar