I'm sorry if this questions is being raised but I'm really new to coding and started to have the first difficult issue and can't figure it out. I have write a simple code like this because I have to learn the return
command:
function multiplyByNineFifths (number) {
return number *(9/5);
};
function getFahrenheit (celcius) {
return multiplyByNineFifths (celcius) + 32;
};
getFahrenheit(15);
but when when I want to run the code in VS it says:
[Running] node "c:\Users\Oerd Bej\Desktop\JavaScript
exercises\tempCodeRunnerFile.js"
[Done] exited with code=0 in 0.088 seconds`
while in DevTools in console it runs perfectly and it gives me the right answer which is 59.
Please can you help me to figure it out what should I do, I have installed node.js and all the necessary plug in in VS but dont know what is wrong or what is the right question that I have to ask in order to understand it well. Every error in VS it breaks my heart
It's because logging is a little different in Chrome than in Node. If you type console.log(3)
in Chrome, it will log 3
, and then the return value of console.log
which is undefined
(because console.log
doesn't return anything). Chrome will always automatically log the function's return value. Node doesn't. It will only log 3
. Node executes the getFahrenheit
function, but this function doesn't return anything. It just computes a number in memory, that's it, so nothing gets displayed. If you want to see the result of this operation you need to log it with console.log(getFahrenheit(15))
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.