₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,346,305 members, 8,522,298 topics. Date: Friday, 20 November 2026 at 10:11 PM

Toggle theme

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 (1819 Views)

1 Reply

I'm Completely Stuck And Need Help With A Javascript Function by cammyjr(op): 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?
Re: I'm Completely Stuck And Need Help With A Javascript Function by bot101(m):
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 Reply

Javascript Function Declaration Syntax: Var... • Help With A Javascript Code • Javascript With NodeJS • 2 • 3 • 4

After Few Weeks Of Kotlin And Material Design Training, I Launched This App! • Aspiring Programmers Come In Lets Discuss • Best Java Web Development Solutions