Jump to content
Sign in to follow this  
Brofenix

Call Function Tested in Exercise 1 Never Taught

Recommended Posts

Hello, this is my first post on the forums after learning HTML and JavaScript for the past 2 weeks. I have a suggestion to make for the JavaScript Functions tutorial, specifically learning how to call a function. The tutorial is very good overall and I am enjoying learning about HTML & JavaScript. As this is my first exposure to coding, my suggestion may be out of place or unusual that I did not know this particular information. However, the JavaScript tutorial never to my knowledge taught me how to call a function the way Exercise 1 at the bottom of the Function tutorial (https://www.w3schools.com/js/js_functions.asp) asked me to do.

The answer to call the function as Exercise 1 asks you to do is to insert the code "myFunction();" after the curly bracket however all throughout the JavaScript and particularly the Function tutorial, the user had been taught to call functions by inserting the code "document.getElementById("demo").innerHTML = myFunction();" after the curly bracket. The "return" statement was not used in Exercise 1 as I had felt I was most comfortable using.

I would suggest strongly that some line or section be inserted in the JavaScript Function tutorial to teach the method of using "myFunction();" to call a function, as I did not understand that functionality and thought the Exercise was impossible to figure out without looking at the answer. Maaaybe the Exercise is designed to teach you to call a function using "myFunction();" but if that is true, in my opinion it is a poor way to teach that tool.

Thank you for your time and in general a great website.

 

Edited by Brofenix

Share this post


Link to post
Share on other sites

The tutorial does say that the function is invoked using the ( ) operator.

Share this post


Link to post
Share on other sites

Be aware that it is always to the benefit of the student to modify the code in the Tryit editor in order to verify your understanding of whatever is presented. In the code you mention it is difficult to guess whether the student would know that the following is equivalent...

var myResult = myFunction(3,4); // call the function
document.getElementById("demo").innerHTML = myResult; // display the result

 

Share this post


Link to post
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
Sign in to follow this  

×