Lesson 9 ? function to parameters?


#1


// Write your function starting on line 3

var perimeterbox = function(length,length,width,width)
{
    return length + length + width + width ;
}
perimeterbox (4,4,4,4);

This is correct I think but has a "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." error


#2

I'm pretty sure it's because you have perimeterbox (4,4,4,4) when it should be (1,1,1,1)

or more efficiently

var perimeterbox = function(length, width) // you only need to have one of each. If this were a different shape you'd have to label it instead with (length1, length 2, length 3, width1, width2, width3) or whatever is best. But since it's a rectangle, both length's are equal and both widths are equal. Only need one length and one width. T

premiterbox(1,1); //bam!


#3

That doesnt work. The lesson ask us to use

return length + length +height + height;

so

var perimeterbox = function(length,lenght,width,width)

will have to work..I dont know whats wrong...


#4

// Write your function starting on line 3

var perimeterbox = function(length,width)
{
return length + width ;
}
perimeterbox(1,1);

I also tried this one...


#5

Oh I see. Then it's probably just the lesson being annoying and too strict. ... as usual lol

So then use your original code but instead

perimeterbox(1,1,1,1);

if that doesn't work please link the lesson so i can see exactly what has it's panties in a bunch.


#6

Please I need help, is it the browser or something else because I think the code is good..Thanks


#7

As I said, put the direct link to your lesson in a post.


#8

O.K. what do you mean by link? the link to my account ?

Here is the code Im using now.

var perimeterbox = function(length,length,width,width)
{
return length + length + width + width
}

perimeterbox (1,1,1,1);
https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/2/1?curriculum_id=506324b3a7dffd00020bf661#


#9

I tried the code online and it works fine...


#10

Hello @kachidousa

The instructions from that link specifically ask for you to create a function called perimeterBox that has only 2 parameters. They even give you an example of a return statement to use. I'm not sure why you have 4 parameters in your function. If you make slight alterations to the function name and the return statement in the code below, you will pass the exercise.


#11

I tried that earlier and it does not work. I tried copying your code and it does not work...
Im getting

Oops, try again. Did you define a perimeterBox function?


#12

I didn't give you code to copy. I selected the code you wrote that was the closest to a solution. Use the instructions.

They want a function called perimeterBox, not perimeterbox. They want the function to take two parameters, not four parameters. They give you a return statement of length + length + width + width.

That should be what you write as code.


#13

I have corrected the perimeterBox , I found that error but I tried all the other ways and nothing...


#14

Post your code anytime you make corrections so we can have a look :slight_smile:


#15

/// Write your function starting on line 3

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

I got it to work , Thanks


#16

Glad you worked it out :slight_smile:


#17

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