/    Sign up×
Community /Pin to ProfileBookmark

Simple function outputs three values when only one is expected!

Hey folks,

I’m just diving into Javascript on Code Academy and I have a real quick question about the code I pasted below. It worked and I passed the section but I’m wondering why I am seeing an output of 25, 25, 50. I expected to just see 25. Something funky happening here?

I’ll past the instructions here:

[LEFT][I]“You are a creature of habit. Every week you buy 5 oranges. But orange prices keep changing!

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.”[/I]
[/LEFT]

code:

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

};

orangeCost(5);

Again the output I see is:

25
25
50

Not a huge problem but I’m trying to grab all the details as I go along.

Cheers for the help!

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@Error404Apr 13.2014 — Is there any other code or HTML on the page since the function you gave only returns 1 value?
Copy linkTweet thisAlerts:
@uncleahweiauthorApr 14.2014 — The only code in the editor was what I pasted in my thread. Most curious.
Copy linkTweet thisAlerts:
@Sup3rkirbyApr 14.2014 — I feel like there has to be some other code, or another step to this. You say the output is '25, 25, 50', which of course is 3 values. The function is only called once and so there would only be one value.

If I take the exact code you posted and run it I simply get '25' and nothing more logged to the console. As far as what you posted in this thread goes there are no errors, syntax, logical or otherwise.
Copy linkTweet thisAlerts:
@uncleahweiauthorApr 15.2014 — Funky! Well at least my code is correct. Thanks for the replies <3
Copy linkTweet thisAlerts:
@JMRKERApr 17.2014 — Question: Did you clear the contents of the console.log before running your program?

It may be showing the results of earlier runs.
Copy linkTweet thisAlerts:
@uncleahweiauthorApr 17.2014 — Nope because I don't know how to do that, ;P. What's the command for it?
Copy linkTweet thisAlerts:
@JMRKERApr 17.2014 — nope because i don't know how to do that, ;p. What's the command for it?[/quote]

f12
×

Success!

Help @uncleahwei spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...