Concerning two parameters in a function with user feedback


#1

So I am currently working on the ninth exercise in Introduction to Functions. I have completed the exercise and I understand how the course wants me to code in this particular situation. I am more curious though, how I can make use of the prompt() command in this situation. Currently this is what I have and it seems to be off a bit.

var perimeterBox = function(length, width) {
return length(2) + width(2)
};
var length = prompt("What isthe length?")
var width = prompt"(What is the width")

console.log(perimeterBox(length, width));

What is wrong with this coding and how can I fix it?


#2

Be more careful when writing, follow the standards. You forgot some ; at the end of sentences and also one " is wrongly positioned (the first one of the second prompt). Try the next code:

var perimeterBox = function(length,width){
return length*2 + width*2
};
var length = prompt("What is the length?");
var width = prompt("What is the width?");

console.log(perimeterBox(length, width));

If this doesn't work, try aislating the multiplications:

 var perimeterBox = function(length,width){
    return (length*2) + (width*2)
    };
    var length = prompt("What is the length?");
    var width = prompt("What is the width?");
    
    console.log(perimeterBox(length, width));

I believe that should work, if the first one doesn't work, then try the second option.

Hope it helps :smile:


#3

Thank you very much for the help. I need to slow down a tad haha, I am very eager to learn!