Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,151 members, 7,807,507 topics. Date: Wednesday, 24 April 2024 at 02:24 PM

I'm Completely Stuck And Need Help With A Javascript Function - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / I'm Completely Stuck And Need Help With A Javascript Function (1710 Views)

Javascript Function Declaration Syntax: Var... / Help With A Javascript Code / Javascript With NodeJS (2) (3) (4)

(1) (Reply)

I'm Completely Stuck And Need Help With A Javascript Function by cammyjr(m): 3:45pm On Apr 23, 2015
Greetings people, please I am stuck here and I need help .


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.


Any help ?
Re: I'm Completely Stuck And Need Help With A Javascript Function by IamGodzilla: 4:40pm On Apr 23, 2015
cammyjr:
Greetings people, please I am stuck here and I need help .


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.


Any help ?

var oranges = [1,2,3,4,5];
function OrangeCost(cost) {
return oranges.length * 5;
}
OrangeCost(5);
Is this what you want?

1 Like

Re: I'm Completely Stuck And Need Help With A Javascript Function by bot101(m): 11:49pm On Apr 23, 2015
cammyjr:
Greetings people, please I am stuck here and I need help .


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.


Any help ?

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

//example
/*
Calculates the price of 5 oranges,
outputs the result to the console &
returns the cost of 5 oranges
*/
var fiveOranges = orangeCost(10);
window.alert(fiveOranges); //calls alert with the result as parameter

1 Like

(1) (Reply)

Create Fake Student I.d. / Should I Build From Scratch Or Use A Framework? / Jamb Website Is Very Bad

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.