So I’m studying Javascript w/ the Javascript - Absolute beginner’s guide book from Kirupa, and I got stuck on the “Return Keyword” (page 35 on the 3rd edition).
So my code looks like this:
function getDistance(time, speed) {
let distance = time * speed;
return distance;
}
let myDistance = getDistance(10,5);
Exactly like it is on the book. But when I run this code, it does not return anything. What did I do wrong?
Yes, using the console.log I managed to display the 50 result. But not on the Visual Studio Code! Like I couldn’t display this “50” in a HTML page, using just this code. I can only display using the “alert” function.
Thank you for your answer! Btw, do you suggest any other programs to run the javascript codes, beside the Visual Studio Code?
VS Code is your code editor, and it is probably one of the best ones out there for web development. To test your app, you’ll need to use the browser and bring up the developer tools to display any console.log messages.
You’ll soon be adding code that will display values directly to the web page. The sections on the DOM will cover all of that, so using console.log is going to be a temporary pain point