Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,153,231 members, 7,818,781 topics. Date: Monday, 06 May 2024 at 02:50 AM |
Nairaland Forum / Science/Technology / Programming / I'm Completely Stuck And Need Help With A Javascript Function (1715 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: 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: 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)
Wordpress Developer Needed / Help A Confused Soul: Data Science, BI Analysis Or Software Development / Sony Vaio I Core7 Laptop For Sale
(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. 12 |