Please help explain 9 to me, urgentt!


hey please i am confused why doesnt this coding work :

// Write your function starting on line 3

var perimeterBox = function (length,width) {
var val = (length + length + width + width);


but this other coding works : ,

var perimeterBox = function(length, width) {
return length + length + width + width;
var newNumber = perimeterBox(10,5)

please explain i am confused as mad lol.


One is using console.log and the other one is using return. Could you give us the error message you receive?


the error message i got from using the console.log method is :
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.


You need to use the return keyword. Not console.log. That's your problem.


i know that lol but why is that?


It doesn't want you to log the information, it wants you to return it, so it can be processed further afterwards.


You want to get into the habit of returning in your function, unless specified otherwise.


oh ok so when am i meant to use 'console.log' and when am i meant to use 'return' regarding variable functions?


Always use return unless specified.


In any case the instructions should guide you what variable names you need to choose and what way of output is required. If words like "console.log, log or print" come up it means that you should use console.log and if you're asked to return something well you need to use return. Return has actually some advantages because the returned value can be used in the program and it can be shown on the screen whereas console.log just shows it on the screen but after this the value is gone. If stuff like this is not mentioned in the instructions it mostly means that it doesn't care in this exercise and if it is missing and the program cares about it is probably a bug but I'm not aware of a case where this is happening in the JS track.


oh ok thank you very much,that makes more sense


thanks for the help and your time