# Simple function outputs three values when only one is expected!

• 04-13-2014, 06:23 AM
uncleahwei
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:

"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."

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!
• 04-13-2014, 01:53 PM
Error404
Is there any other code or HTML on the page since the function you gave only returns 1 value?
• 04-13-2014, 07:28 PM
uncleahwei
The only code in the editor was what I pasted in my thread. Most curious.
• 04-13-2014, 08:30 PM
Sup3rkirby
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.
• 04-14-2014, 08:08 PM
uncleahwei
Funky! Well at least my code is correct. Thanks for the replies <3
• 04-16-2014, 07:28 PM
JMRKER
Question: Did you clear the contents of the console.log before running your program?
It may be showing the results of earlier runs.
• 04-16-2014, 08:09 PM
uncleahwei
Nope because I don't know how to do that, ;P. What's the command for it?
• 04-16-2014, 10:12 PM
JMRKER
Quote:

Originally Posted by uncleahwei
nope because i don't know how to do that, ;p. What's the command for it?

f12

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.11460 seconds
• Memory Usage 2,360KB
• Queries Executed 11 (?)
Template Usage (20):
• (1)bbcode_quote_printable
• (1)footer
• (1)gobutton
• (1)navbar_moderation
• (1)navbar_noticebit
• (2)option
• (1)spacer_close
• (1)spacer_open

Phrase Groups Available (3):
• global
• postbit
Included Files (19):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/class_bbcode_alt.php
• ./includes/class_bbcode.php
• ./includes/functions_bigthree.php
• ./includes/functions_notice.php

Hooks Called (41):
• init_startup
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• bbcode_fetch_tags
• bbcode_create
• bbcode_parse_start
• bbcode_parse_complete_precache
• bbcode_parse_complete
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates