+ 2
module 12 - functions
there was a question in this module, that I think is incorrect. the question was: What will be the output of this code? function divide(x,y) { return x/y; } divide(6,3); Answers 2 3 nothing The answer should be two (I checked this in the console as well to be sure). but the answer was nothing and I can't see why and can only assume this is a mistake.
3 odpowiedzi
+ 4
I would say "nothing" is correct because you never print the value.
You just call the function, which returns the value. But then nothing happens with this value.
.
To get an output you would need to write console.log(divide(6,3));
+ 2
Try this small code:
function divide(x,y){
return x/y
}
divide(6,3)
console.log(divide(4,2))
res = divide(9,3)
console.log(res)
divide(6,3) -> value is lost
divide(4,2) -> console.log()
-> output 2
divide(9,3) -> res gets 3
-> console.log() -> output 3
+ 1
Denise Roßberg
yes that makes sense, I was checking it in the browser console which would return a value - thanks