+ 2
Code acts differently on different IDEs
I'm practicing HTML/CSS and JavaScript on two different apps (Sololearn and another IDE called "EASY HTML"). The problem is that my jscript codes run normally on Sololearn but seems to have issues when I run them on EASY HTML. Especially when I use functions (that I write in the js area) and insert them in the <script> tag in the HTML area. Example: (in js) function b(name){document.write("Sam");} (In html) <script>b(name)</script>. In Sololearn, it displays "Sam" but in the other IDE, it says "Error:b not declared". I don't know if anyone else has had this problem.
14 Respuestas
+ 2
SolomonDavid Akesoba Okay... I see the issue.
Try running this code in SoloLearn. Then run the code in the Easy HTML app.
https://code.sololearn.com/W3W79U2XwPbC/?ref=app
You can view the console in that app by clicking the rectangular shaped icon after you click on the Results pane.
You will see that the JS line will be listed 3rd in the Eazy HTML app.
However, it's listed 2nd in the SoloLearn app. This will explain why the code loads differently.
+ 3
SolomonDavid Akesoba
If the scripts are identical in both the SL Code Playground editor and in the IDE, it appears you will need to explicitly reference the JS script file in your HTML head tag.
For example, if your JS file is saved as [myapp.js] in the same folder as the HTML file, something like this should work:
<script type="text/javascript" src="myapp.js"></script>
However, I'm not seeing a <link> tag for your CSS and you haven't mentioned an issue with differences in styles. 🤔
If you are using a similar online editor, it's likely the editors are referencing the JS in different places.
The SL Code Editor loads the JS before the b() function is called while the other one loads it after.
Either way, there is so much going on in this HTML that is in the places using the wrong practices, I'm surprised there aren't more issues.
Anyway, I've not heard of the tool your are referring to: Easy HTML. Can you send a link so we can understand what you're using?
+ 3
SolomonDavid Akesoba Ah... That makes sense.
Keep at it... The only way to learn is to make mistakes you can learn from. That's the secret to my success. 😉👌
+ 2
SolomonDavid Akesoba 👌
Also... What resource material are you referring to in learning how to build this code?
There are quite a few issues in your code you'll want to unlearn and avoid... like using embedded script tags to call Javascript functions for the purpose of outputting to your page in a specific location. That output isn't guaranteed to appear where you placed it.
I'm actually surprised it worked as it does.
+ 1
David Carroll the IDE has the same code input methods as SL i.e. html,css and js are all in the same place (I wish I could share photos here) so there's really no need to insert a link for the js (just as we don't insert links for that in SL)
+ 1
David Carroll oh. You're right. It runs the HTML codes before it adds the jscript
+ 1
I'm just combining all I understand from SL so far. But yeah, I need to relearn how to add JavaScript to a page.
+ 1
David Carroll and the procedure for mine.
0
I could say 2 possible problems:
1. You inserted the script after you called the function
2. You didn't insert the script
0
Airree
1. How?
2. I did
0
Airree this is what I did
https://code.sololearn.com/W2ANyiYUVx22/?ref=app
0
Well, I don't know how your IDE works, but I can say that it's not that good if a practice to use document.write to fill elements or to include 12 scripts for optimalization. You might want to try and find a more suitablr solution to your problem (for example, just writing the words)
Lovely code btw
0
Airree
So I should have just repeated the words instead of using a function to automatically insert them? I actually did that thinking it would be more efficient.
Thanks💜.