6/13 - Error despite receiving correct output


#1

I've tried to answer this exercise two different ways, but both give me different errors despite giving the correct output.

The first;

var orangeCost = function (number) {
var number = price * 5;
console.log("The price of an orange is $" + number);
};

orangeCost(price = 5);

When I execute the code I get; "Oops, try again. Hmm, it looks like your orangeCost() function doesn't return 25 when the cost of an orange is 5." (despite the console log printing "25")

I removed the string from the above line so it just reads

console.log(number);

But when I execute, I get this error: Oops, try again. Hmm, it looks like your orangeCost() function doesn't return 50 when the cost of an orange is 10.

What am I doing wronghere?


#2

instead of:

orangeCost(price = 5);

just put

orangeCost(5);

#3

Hey, thanks for the swift reply. I changed the code, but even though it still spits out the correct answer (25) I still get the error

" Oops, try again. Hmm, it looks like your orangeCost() function doesn't return 50 when the cost of an orange is 10."


#4

This is what I did:

var orangeCost = function(name) {
console.log(orangeCost * 5);
orangeCost("$5")
}
I do not know where you got "price", but just look at this, and you'll see what you got wrong. Hope it helped!:smiley:


#5

Thanks for the reply. When I try to run your code, the Codeacademy window freezes up and stops working. The reason I originally declared "price" was I assumed you had to set the number for it to multiply by.

Weirdly enough I managed to get it to work by going to the previous exercise and modifying the function in that.

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

orangeCost(5);

I think I messed up by using console.log to call whatever was being multiplied by 5 rather than the product of what was being multiplied?

At any rate, thanks all for giving advice.


#6

For anybody else having trouble with # 6:


#7

Dangerous because if you call this function if would go:

print orangeCost * 5 probably NaN as orangeCost is a function and not a number.
call the function again:
print orangeCost * 5 probably NaN as orangeCost is a function and not a number.
call the function again:
print orangeCost * 5 probably NaN as orangeCost is a function and not a number.
call the function again:
...

#8

The main problem is that it just expects one single number as output and not a string explaining what this number means.


#9

Oh my I just noticed mine crashes :grin: Wonder how my code changed? :neutral_face:

Fixed it. :grinning:


#10

I am working in spanish but this solution doesn´t work for me, If I use costonaranja instead costoNaranjas it works. What happened? Why is important the capital letter?


#11

I don't get it.

var orangeprice = function (price){
var total = price * 5;
console.log(total);
};
orangeprice(5);

And I get 2 results instead of just one 25.


#12

@jhcortes and @ibelde In general the name of a variable is only important for you and the one you write your code for, but for the exercises you are not the only one calling them. To see if your code is working there are some test run on your code which often expect that the variables are named like it is described in the instructions. If they aren't then these test might fail although your code must not be wrong.


#13

but how can we go ahead?


#14

you can for example run your code in labs repl.it, there are no test function just an open enviroment.


#15

ready, I ran the code and was ok?, now? How can I translate this result to my lessons?


#16

Copy paste it? What exactly do you want to do?


#17

I´m trying to learn how to program, this is the “big” code
var costoNaranjas = function (precio) {
var val = precio * 5;
console.log(val);
};
costoNaranjas(5);

In my lerning room doesn´t work but in the link you gave me (labs repl.it) work.
If the code doesn´t work in my dashboard is not possible to me to go ahead with my classes. How can I fix in mi learning module?


#18

could you post the code for your exercise as this seems to be ok from the syntax.


#19

yes, i think is a bug in the lesson. i do not know how to go to the next level,


#20

Yes maybe it's a bug and your better of going on with the rest and leave this exercise for now. But could you post the link to the exercise?