Author Topic: Javascript help?  (Read 522 times)

I'm using codecademy because I find it really easy to learn some languages there and it's telling me I didn't define variable "orangecost":
Quote
var orangecost = function (price) {
var cost = price * 5;
console.log(cost);
}
orangecost(5);
what am i doing wrong?

I just put it in a simple html file, changed console.log (is this what codeacademy uses?) to document.write and it worked fine

Strange.
Maybe the instructions on it will help?
Quote

    You want to declare a function that calculates the cost of buying 5 oranges.
    You then want to calculate the cost of the 5 all together.
    Write a function that does this called orangeCost().
    It should take a parameter that is the cost of an orange, and multiply it by 5.
    It should log the result of the multiplication to the console.
    Call the function where oranges each cost 5 dollars.
And the hint:
Quote
What is the one bit of input that changes each time? It would be the price. So give your parameter the name price. And when you call your function, put in a number for the price to see how much 5 oranges cost!

I just pasted that into codeacademy myself
It said I didn't do the exercise right, cuz I just clicked a random one, but it worked and printed 25


offtopic: that's an expensive as forget orange

idk, something weird happened
probably just a glitch with that exercise
copied and pasted someone's code from the help forum there (it's slow so i posted here)
thanks!