Lesson 9 is this correct


#1

console.log(perimeterBox(legth*width)) logs NaN is this correct shouldn't it log the perimeter of the box?

var perimeterBox = function(legth, width){
    
    return legth+legth+width+width;
};
    var legth = 10
    var width = 12
console.log(perimeterBox(legth*width))

#2

How many parameters does your function have?
How many arguments are you giving it?


#3

4 parameters and 2 arguments is think its my first java cours so no sure


#4

the problem is its says correct but i dont understand why it is correct


#5

This language is called JavaScript, Java is a (very) different language.

No that's not at all right. Your function has two parameters, and you're supplying one argument.

You need to supply exactly as many arguments as your function expects. For example, if you have a function that adds two numbers, then it's going to expect two arguments. If you give it only one argument, it will not be able to carry out its task.


#6

Okay, so if i do it like this I get the correct outcome

var perimeterBox = function(legth, width){
    
    return legth+legth;
    return width+width;
};
    var legth = 1
    var width = 1
console.log(perimeterBox(legth+width))

but it says

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.


#7

now i have 2 parameters and i have 2 arguments right


#8

and sorry for the javascript confusion just started yesterday on coding


#9

Was there a problem with the function? What problem were you solving when changing it?


#10

i was trying to solve the problem that i only had one argument and 2 parameters. Thats why i made 2 arguments instead of one atleast i think i did.

So i split the legth and the width in 2 arguments instead of one and now the printed outcome is correct, the awnser i get is the perimeter of the box but the course says its wrong.


#11

If the function has two parameters and should have two parameters, then there is nothing to change about that.

If you aren't supplying a suitable number of arguments to the function when calling it, then that is something to change.

Returning twice is not possible, you can't leave the function twice.


#12

oke so my parameters are the (legth, width) behind the function rigth?
my arguments are the return length+length and return width + width?
but i cant use return 2 times in a row so i need to use somting els for return?

because when i use 2 parameters i need 2 arguments am i correct?


#13

Read the stuff that is above the table of contents: https://en.wikipedia.org/wiki/Parameter_(computer_programming)

Generally, don't guess. If you don't know, then find out.


#14

oke i get it the arguments are what we call the stuff behind the function we give them difrent names so it makes more sence to us like length and width in this case

the parameters are the value that we give the arguments


#15

The parameters are the variables used to receive and refer to the arguments.
The arguments are the values that are given to the function.

The list of parameters says how many arguments a function expects. A function that expects two arguments should therefore have two parameters.

When using a function that has two parameters, one should supply two arguments.

What separates arguments in a function call? No guessing. If you don't already know it, then that's something to google or refer back to earlier material if you recall it having been explained already and where it was explained. If you guess then you're going to be making some change that you don't really know if it has the desired effect or not. Perhaps it's got a similar effect, but isn't the same, and then you'll have something even more difficult to debug later and you don't understand what you wrote because you were guessing, so you can't reason about it and debugging gets really difficult.
If you only ever add things that you know what they do, then you understand each thing that's happening, you can reason about it. Stick with the things you know and expand your vocabulary so that you can use more things


#16

@webslayer69022 Check your spelling, semicolon placement, and parameter usage.


#17

var perimeterBox = function(length, width)
{
return (width+length)*2;
}

console.log(perimeterBox(1+1))

so this should be right the length, width behind function are the parameters because they do not yet have value there

the arguments are the 1+1 in the bottom wich give value to the parameters

but still the outcome is NaN


#18

got it the + in the bottom should have been a ,


#19

thanks both for the help!


#20