Stats: 3,191,891 members, 7,945,876 topics. Date: Wednesday, 11 September 2024 at 08:31 AM |
Nairaland Forum / Science/Technology / Programming / I'm Completely Stuck And Need Help With A Javascript Function (1737 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)
12-year Old Nigerian Is A Certified Java Programmer / Jamb Website Is Very Bad / I Need Help With This Php Code For Email And Sms Autoresponse
(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. 14 |