Help!Confuse with the result with console.log and return


#1


I m new to programming, i m confuse why i get different results when i use console.log instead of return. when i used return, i only get one result which is 12 but when i used console, i get 12 and a 4 below.

https://www.codecademy.com/en/courses/javascript-beginner-en-6LzGd/2/1?curriculum_id=506324b3a7dffd00020bf661


Oops, try again. It looks like your perimeterBox function doesn't return the correct perimeter (4) for a width of 1 and a length of 1.


var perimeterBox=function(length,width)
{  console.log (length +length + width + width);};
perimeterBox(2,4)


#2

printing to console has the effect of showing text.. in the console. It does nothing else, so unless that's specifically what you want to do then that's not what you want to use.

return exits the current function and gives the result to the caller which can do whatever it wants with the result, including printing it


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.