Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,393 members, 7,958,119 topics. Date: Wednesday, 25 September 2024 at 09:07 AM |
Nairaland Forum / Science/Technology / Programming / Andela Lab Solution(fizzbuzz) (2462 Views)
Join The Andela Learning Community; Powered By Microsoft / Andela, Udacity And Google Team Up To Teach Nigerians Android Development 4 Free / Andela Will Empower Africa's Next Generation Of Great Technical Leaders (2) (3) (4)
Andela Lab Solution(fizzbuzz) by Enygma: 10:18am On Jun 25, 2016 |
Hello everyone, I need you guys to look into this code for me. I have completed 93% of the Andela Homestudy,I need your urgent help on this, thanks! JAVASCRIPT LAB QUESTION Create a function fizzBuzz to return 'Fizz', 'Buzz', 'FizzBuzz', or the argument it receives, all depending on the argument of the function, a number that is divisible by, 3, 5, or both 3 and 5, respectively. When the number is not divisible by 3 or 5, the number itself should be returned. MY Solution (function fizzBuzz () { for (i=1;i<101;i++){ if (i % 15 === 0){ console.log('FizzBuzz'); } else if(i % 3 === 0) { console.log('Fizz'); } else if (i % 5 === 0 ){ console.log('Buzz'); } else { console.log(i); } }; })(); AND THESE ARE THE ERRORS I GET EACH TIME......... THERE IS AN ERROR/BUG IN YOUR CODE Results: 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 52 53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 62 Fizz 64 Buzz Fizz 67 68 Fizz Buzz 71 Fizz 73 74 FizzBuzz 76 77 Fizz 79 Buzz Fizz 82 83 Fizz Buzz 86 Fizz 88 89 FizzBuzz 91 92 Fizz 94 Buzz Fizz 97 98 Fizz Buzz /home/ubuntu/Applications/andelabs-server/tmp/andelabs_5765ac22e83de519007349fd_565c28fd9c306a14009680f2.js:21 module.exports = fizzBuzz; ^ ReferenceError: fizzBuzz is not defined at Object. (/home/ubuntu/Applications/andelabs-server/tmp/andelabs_5765ac22e83de519007349fd_565c28fd9c306a14009680f2.js:21:18) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17) at require (module.js:380:17) at Object. (/home/ubuntu/Applications/andelabs-server/tmp/5765ac22e83de519007349fd-565c28fd9c306a14009680f2-test.js:1:78) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) |
Re: Andela Lab Solution(fizzbuzz) by maekhel(m): 1:38pm On Jun 25, 2016 |
function fizzBuzz (i) { if (i % 3 === 0) { console.log('Fizz'); } else if (i % 5 === 0 ){ console.log('Buzz'); } else if (i % 3 === 0 && i % 5 === 0) { console.log('FizzBuzz'); } else { console.log(i); } Not tested though typing from a phone. |
Re: Andela Lab Solution(fizzbuzz) by Nobody: 1:52pm On Jun 25, 2016 |
function fizzBuzz(test){ var str=""; if((test%3)==0){ str+="Fizz"; } if((test%5)==0){ str+="Buzz"; } return str || test; } |
Re: Andela Lab Solution(fizzbuzz) by Fulaman198(m): 4:24pm On Jun 25, 2016 |
maekhel: That should work based on reading it |
Re: Andela Lab Solution(fizzbuzz) by forap(m): 5:56pm On Jun 25, 2016 |
The question says 1: create a function (which means write a simple function), 2: or the argument it receives (which means the function accepts a parameter) My question, why did you decide to write a self invoking function, and also how do pass a parameter to such a function, without using JS closure? Always keep your solutions simple.
1 Like |
Re: Andela Lab Solution(fizzbuzz) by Enygma: 9:40pm On Jun 25, 2016 |
Woww, I appreciate you all. Got it guys,you made it possible. Thanks |
(1) (Reply)
Paragon NTFS 15.5.71 Crack For Mac FREE / Please Help An Upcoming Programmer / FIFA 2018 Data Analysis (AI) Update
(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. 13 |