I'm practicing JavaScript (just started this week) on Visual Studio Code with the Quokka.js extension. I started learning about functions, this is my first code:
function calculateTip(price, percentage) {
console.log('calculating tip')
return (percentage/100) * price;
}
calculateTip(50, 18);
This function above only prints me the text 'calculating tip'. It returns nothing (no result from the calculation: percentage/100*price) although I have written the return code.
// function expression
var divideByN = function(number, n) {
return number / n;
}
divideByN(18, 3);
The function expression above returns me nothing (it should return 18/3).
// anonymous function
(function(number, n) {
console.log('I am an expression');
return number / n;
})(18, 3);
The anonymous function above only prints me the text 'I am an expression'. It should return number/n.
So, console.log seems to be working alright, but the functions/return calculations themselves not. At least they are not returning any numbers or text, not even undefined or errors or NaN. What could be the cause of this in vscode+Quokka.js? Do you have any alternative options for learning JS functions in vscode?
(keywords and keyphrases function returns nothing, nothing returned out of a function, function no return, function prints nothing, javascript function returns nothing, javascript function no return, javascript function not working, javascript functions not working in vscode)