Lesson 6


#1

my code:
var orangeCost = function(cost) {
var price = cost * 5;
console.log('5 oranges cost' + ' ' +price);
};
orangeCost(2);

please, help. i wanted to add a phrase before the result. Why do I get as result:
5 oranges cost 10
5 oranges cost 25


#2

You should only get

5 oranges cost 10

as a result. You also getting the other message?


#3

yes, I`m getting both of them


#4

var orangeCost = function(cost) {
    var price = cost * 5;
    return price;
};

console.log('5 oranges cost ' + orangeCost(2));

I think ti was caused by missing return. Whatever it was, this will work.


#5

i think i got it)
cosole.log inside the function show the result. if you want to use the result in sentence, as i wanted, then must use return and console.log outside the function...


#6

5 oranges is not going to cost the price of 2 oranges. The exercise wants you to find the price of 5

console.log("5 oranges cost" + orangeCost(5));


#7

orangeCost(x) - x is the cost of 1 orange, then function multiplises to 5


#8

yeah but he had 2 in there, 2 oranges x 5 is 10 not 25.

5 oranges x 5 is 25


#9

Also this is simpler and works

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

orangeCost(5);

#10

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

result - 10. 2 - is the cost of 1 orange, then 2*5 = 10
if orangeCost(5) - the cost of 1 orange is 5, and 5*5 = 25

or am i wrong?


#11

youre setting not the amount of oranges in orangeCost, youre setting the cost of 1 orange)))


#12

Yes orangeCost(2) is meaning a single orange is 2$ £2 or whatever

Ignore the 2 completely, you're buying 5 oranges not 2.


#13

The thing is you have 5 in the function, which is the number of oranges, and you're sending price for 1 orange. He sent 2, so I worked with his example. You can send 5, I can send 7, that's no the issue.


#14
You'll need to use 'return' in your function and then console.log outside. See below

var orangeCost = function(cost){
return (5 * cost);
};

console.log("5 oranges cost " +orangeCost(5));