Jump to content

I do not understand why simple code is not running!


igor.learner

Recommended Posts

Hello. I am doing a tutorial on youtube, and a guy (teacher, i am not sure if I can advertise him here) is showing a lesson - "Calling function from another function" on a video, he is writing and generating the code to the web page, but I write the same code - nothing happens. My code is: <html><head><title>Tutorial</title><script type="text/javascript">function doFirst() { document.write("one two three"); }function doSecond() { document.write("My name is Juris"); }function start() { function doFirst(); function doSecond(); } start();</script></head><body></body></html> - it is very basic, but it is not popping on my screen. I do not understand why? I have checked everything for mistakes. Does somebody know the answer?

Link to comment
Share on other sites

The start() function should be called in the <body> section of the document, content in the head isn't meant to be rendered (thought browsers do it anyways since they're designed to save bad coders from themselves). But even then, document.write() will probably cause trouble, it's a good idea to never use it. If you want to display some text on the page, manipulate the innerHTML or create a text node and append it to the body element.

function doFirst() {	document.body.innerHTML += "one two three";}

Link to comment
Share on other sites

Deirdre's Dad thanks !I was literally looking at my code about 5 times and comparing it to the code on the video, but somehow I did not see the mistake you wrote about. It works now. In programming you need such a punctuality and, how is it in english, "proof reading", everything can just not work if you do not put one word in :) Foxy ModIt is something new for me, it works as well. I will try to remember that.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...