Lesson. 6 Dont repeat yourself help


#1

var orangeCost = function(cost) {
console.log("oranges" + " " + "cost" + " " + cost);
}
orangeCost("5");
this is the code I have I don't know how to multiply the number by five so can someone please help


#2

Hey @iwannamakevideogames! The problem with that is when you call it never put it as a string.

Just do orangeCost(5);

Hope that helped!


#3

I figured out that the problem was I wasn't doing
console.log(cost * 5);
I found this out by surfing through the forums for people having problems with this too


#4

spoiler

var orangeCost = function(price) {
var val = price * 5;
console.log(val); };

orangeCost(5);


#5

Why did you put the val? What does that mean?


#7

You're literally the only person out of all the forums on this particular exercise that typed it correctly..


#8

Why this doesn't work?!

var orangeCost = function(price);
{
console.log("price*5");
};
orangeCost(5);


#9

there should not be a semicolon at the end of the first line. The structure should look like this:

var functionName = function(parameter) {
  //do some stuff ;
  //do some other stuff if you need to ;
};

Take a look at where all of the brackets and semicolons are and compare it to your code. Hope that helps!


#10

hope it will help
var orangeCost = function(price) {
console.log(price*5);
};

orangeCost(5)


#11

Thank you very much!


#12

hola tengo esto pero no me funciona por fa me ayudan

var costoNaranjas = function (precio) {

console.log (precio*5);
};

costoNaranjas (5);


#13

var orangeCost = function(price){
var value = price * 5
console.log(price*5);
}

console.log(orangeCost(5));

this worked for me and printed out the text i'm not sure that would be right as it dosen't write the answer to the task


#14

ok it seemed to work for me


#15

My issue is that my function works but it prints to console twice.

var orangeCost = function(price) {
var x = price * 5;
console.log("Oranges are " + x + " dollars today");
}

orangeCost(5)


#16

Try using "return x " at the end


#17

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