0
Using JS tab in SL Playground
Why is it when I put my JavaScript code in the JS tab of SL code playground I get an error? The same JavaScript code placed inside the <script><\script> tags in the HTML code runs without issues. The same JavaScript code placed in a separate file run outside of SoloLearn playground also runs without issues. Is there a special setting I need to do to make it run in the playground? Or is this a limitation of SL playground?
3 Antworten
+ 3
Since we lack context to what error actually occured, I'll just take a wild guess and assume that it's an instance of script loading before DOM. Try referring to these threads:
https://www.sololearn.com/Discuss/1190390/?ref=app
https://www.sololearn.com/Discuss/88797/?ref=app
https://www.sololearn.com/Discuss/456796/?ref=app
https://www.sololearn.com/Discuss/510702/?ref=app
+ 2
Looking at your calculator code, if you change...
var display0 = document.getElementById('display0');
var display1 = document.getElementById('display1');
var isNewEntry = true;
...at the top to...
window.onload = function () {
var display0 = document.getElementById('display0');
var display1 = document.getElementById('display1');
var isNewEntry = true;
}
...I think it works.
Really nice code by the way!
+ 1
Thanks, Russ and Hatsy Rei !
Indeed it just needed the window.onload = function(){}
Thank you, I learned something new again.
My calculator code now runs with the js code in the JS tab rather than within the html code itself.
https://code.sololearn.com/Wo4pC0r83961/?ref=app