+ 1

What am I missing or what did I do wrong?

I want to make it so that when the code is run, and the user hits cancel, the text will not appear, but I've tried everything I can think of and the text stays put whether I click cancel or OK. If someone could tell me what I did wrong or am missing, I would much appreciate it. Thank you in advance. https://code.sololearn.com/WAg09I9WZk5f/?ref=app https://code.sololearn.com/WAg09I9WZk5f/?ref=app

23rd Oct 2017, 9:50 PM
jacksonofgames 28
jacksonofgames 28 - avatar
2 Respostas
+ 4
> The confirm() method return a value that you can store in a variable to test it (or you could test it directly, whitout storing the result ^^), but you you need to correctly do it (you cannot assign twice inline -- ie: a = b = 42 -- and as you've done the returned value by confirm() is lost -- not stored at all)... > You doesn't need a function in your if statement, and if you do, you need to execute it (actually the function body will never run unless you call the function elsewhere, as you only declare it). > You need to have access to the variable storing the confirm() result, and as you're right to embed your code in a function assigned to the onload event, you could store all your code in the main function (the other way would be to declare the 'box' variable as global, set it in the onload function -- 'notification', it doesn't need to be a named function ;) -- and use it in an outside called function)... > Finally, as you name 'body' the variable storing the reference to the element 'stuff', you need to use it (and not 'stuff') to access the element (and delete its childs)... window.onload = function() { var box = confirm("'The Story of My Life' is very boring, are you sure you want to proceed?"); if (box == false) { var body = document.getElementById("stuff"); var kids = document.getElementById("kids"); var heading = document.getElementById("heading"); var text = document.getElementById("text"); body.removeChild(heading); body.removeChild(text); } }
23rd Oct 2017, 10:17 PM
visph
visph - avatar
+ 2
Thank you very much. That was a very detailed answer.
23rd Oct 2017, 10:32 PM
jacksonofgames 28
jacksonofgames 28 - avatar