₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,326,780 members, 8,428,093 topics. Date: Tuesday, 16 June 2026 at 09:20 PM

Toggle theme

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

Nairaland ForumScience/TechnologyProgrammingI'm Completely Stuck And Need Help With A Javascript Function (1805 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 CodeJavascript With NodeJS234

Someone Should Help Me Solve This C++ Question PleaseI Need A Competent Website BuilderJoshua Agboola: 10-year-old Nigerian Programmer Who Has Developed Games And App