NewStats: 3,263,674 , 8,180,989 topics. Date: Saturday, 07 June 2025 at 08:59 AM 1963j6z3e3g |
Dairy Of Javascript Challenge (2264 Views)
(1) Go Down)
Capslock01: 11:34am On Apr 11, 2022 |
Hi all, I'd be documenting the 30 days challenge of JavaScript I just ed, though the challenge is now at day 7 but it's never late. PS: I'm just way below average JavaScript with no experience. Hence, most codes here will not be too refined or optimized. I'd appreciate all suggestions to make my codes more optimized. |
Capslock01: 11:37am On Apr 11, 2022 |
Day 1 Array Sum Create a function that calculate the sum of an array. The function should receive an array as it's parameter and return the sum of the numbers in that array. For example: sumOfArray([1, 5, 4]) // returns 10; sumOfArray([1, 2, -3, 5]) // returns 5; |
Capslock01: 11:40am On Apr 11, 2022 |
Capslock01: // Day 1 Solution const sumArray = function (Array) { let sum = 0; for (let i = 0; i < Array.length; i++) { sum += Array[i]; } console.log(sum); } const arrayToAdd = [1, 2, 3 , 8]; //Output 14 const arrayToAdd1 = [9, 19, 73] //101 sumArray(arrayToAdd); sumArray(arrayToAdd1) 2 Likes |
Capslock01: 11:44am On Apr 11, 2022 |
Day 2 FizzBuzz Create a function that takes an integer as its input. The function should print all numbers from 1 to n but follow these rules as well: - If the number is divisible by 3, print Fizz in its place - If the number is divisible by 5, print Buzz in its place - If divisible by both 3 and 5, print FizzBuzz For example: Input => 3 Output => 1 2 Fizz Input => 15 Output => 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz |
Capslock01: 12:15pm On Apr 11, 2022 |
Capslock01: // Day 2 Solution // Fizz, Buzz, FizzBuzz function counter (numberInput) { for (let i = 0; i <= numberInput; i++) { if (i % 3 === 0 && i % 5 === 0) { console.log('FizzBuzz'); } else if ( i % 5 === 0) { console.log('Buzz'); } else if (i % 3 === 0) { console.log('Fizz'); } else { console.log(i); } } } counter(15) |
Deicide: 2:30pm On Apr 11, 2022 |
Capslock01:Are you new to JavaScript? |
Capslock01: 4:07pm On Apr 11, 2022 |
Deicide: Kind of. But; I've got knowledge of how things work. As I've done some basic projects with it though. |
LikeAking: 4:17pm On Apr 11, 2022 |
Capslock01: I hope u ar not copying ans from d web, some spying things. Any way you are doing good. |
Deicide: 4:20pm On Apr 11, 2022 |
Capslock01:I was just wondering why you didn't use the reduce function for the Array sum 1 Like 1 Share |
Capslock01: 5:29pm On Apr 11, 2022 |
LikeAking: Lol. I'm not copying answers from the internet BUT whenever I'm stuck, I look up things but I do not copy and dump codes. I feel looking things up on stackoverflow and other platform is part of learning process and programming. BUT I do not copy and dump codes Thank you so much. You're also welcome to drop any solution even to the ones I've done. If there's a better way of doing things. |
Capslock01: 5:38pm On Apr 11, 2022 |
Deicide: Oh! You're right. I never thought of it. But then, if I had thought of it. I'd have avoided it because the challenge is to avoid built in method to get some things done. Like in Day 7. Which is today's task. It was asked to sort an unorganized array without using the sort() method. |
qtguru(m): 6:37pm On Apr 11, 2022 |
I think you are doing well keep up the thread, you will learn about reduce and the rest as time goes on, I think everyone learning should create a thread to track their progress.
|
Biggerbros234: 6:38pm On Apr 11, 2022 |
qtguru:Hi qtguru. What do you think about zapier and Zoho on upwork? |
qtguru(m): 6:50pm On Apr 11, 2022 |
Biggerbros234: They exist on Upworks, if you use them you have to search for gigs using those keywords, infact more platforms are jumping up these days. Another is Webflow, there are so many Webflow gigs. |
Capslock01: 10:59pm On Apr 11, 2022 |
qtguru: Wow! Thanks for dropping by qtguru. And thanks for the compliment too. Yeah, you're right! Like what I've learned in the few days I started this challenge is really amazing. Even things I know before are better understood solving some questions of the challenge. |
Capslock01: 11:06pm On Apr 11, 2022 |
Day 3 FizzBuzz Pro Max Write a function that takes an array of numbers and returns an array that contains arrays where each array contains the output that would have been spat out if the FizzBuzz function was called on the number [4, 10, 6] => [[1,2,Fizz,4], [1,2,Fizz,4,Buzz,Fizz,7,8,Fizz,Buzz], [1,2,Fizz,4,Buzz,Fizz]] |
Capslock01: 11:12pm On Apr 11, 2022 |
Capslock01: // Day 3 Solution function takesArray (theArray) { let arrTakes = []; for (let element of theArray) { for (let i = 0; i <= element; i++) { if (i === 0) { arrTakes.push() } else if (i % 5 === 0 && i % 3 === 0) { arrTakes.push('FizzBuzz'); } else if ( i % 5 === 0) { arrTakes.push('Buzz'); } else if (i % 3 === 0) { arrTakes.push('Fizz'); } else { arrTakes.push(i); } } } const outputArray = console.log([arrTakes]); } takesArray([4,15,6]) PS: This code is not as optimized as I wanted it to be. The output gave the required results but it's not as packed as the challenge require. I'll appreciate if anyone can post a more optimized solution or give a pointer to how things can be done perfectly. Thank you |
Capslock01: 9:45am On Apr 12, 2022 |
Day 4 Create a function that takes in an array of objects containing properties: name, age and level. It should return an array of strings where each string is a concatenation of all values contained in the object separated by a slash For example: [{name: ‘Seun’, age: 23, level: ‘100 level’}] => Your function => [‘Seun/23/100 level’] [{name: ‘Seern’, age: 23, level: ‘500 level’}, {name:’BBBgh’, age:’twenty three’, level: ‘year 1’}] => Your function => [‘Seern/23/500 level’,’BBBgh/twenty three/year 1’] |
Capslock01: 9:47am On Apr 12, 2022 |
Capslock01: // Day 4 Solution //Combine Properties of Array with Slash function callArrayOfObject (objects) { const emptyArray = []; for (let i = 0; i< objects.length; i++) { const theIteration = (`${objects[i].name}/${objects[i].age}/${objects[i].level}`); emptyArray.push(theIteration); } console.log(emptyArray); } const arrayOfObject = [{ name: 'Seun', age : 23, level : '100 level' }] const arrayOfObject1 = [{ name : 'Seern', age : 23, level : '500 level' }, { name : 'BBBgh', age : 'twenty three', level : 'year 1' }] callArrayOfObject(arrayOfObject); callArrayOfObject(arrayOfObject1); |
Capslock01: 4:16pm On Apr 12, 2022 |
Day 5 Create a function that does the opposite of what yesterday’s function did. It takes the output of the function and returns the input. Therefore, your function should take an array of strings containing the name, age and level values separated by a slash. Your function should return an array of objects that have the name, class and level keys with their corresponding values. For example: [‘Seun/23/100 level’] => Your function => [{name: ‘Seun’, age: 23, level: ‘100 level’}] [‘Seern/23/500 level’,’BBBgh/twenty three/year 1’] => Your function => [{name: ‘Seern’, age: 23, level: ‘500 level’}, {name:’BBBgh’, age:’twenty three’, level: ‘year 1’}] 1 Like |
Capslock01: 4:18pm On Apr 12, 2022 |
Capslock01: // Day 5 Solution //Unpack Slashed Array of Day 4 Challenge function returnObjectArray (arrayObject) { const trial = []; for ( let i = 0; i < arrayObject.length; i++) { const splitTheString = arrayObject[i].split('/'); const testingObject = ([{ name: splitTheString[0], age : splitTheString[1], level : splitTheString[2] }]); trial.push(testingObject); } console.log(trial); } returnObjectArray(['Seun/23/100 level']); returnObjectArray(['Seern/23/500 level', 'BBBgh/twenty three/year 1']); 1 Like |
LikeAking: 5:40pm On Apr 12, 2022 |
Capslock01: Clapps!!!!!!!!!!! |
Capslock01: 9:01pm On Apr 12, 2022 |
LikeAking: Wawwwu! Thank boss. |
africanman85: 4:06am On Apr 13, 2022 |
Nice
|
Andrenalin: 7:36am On Apr 13, 2022 |
i love this lets keep it going...
|
Capslock01: 9:49am On Apr 13, 2022 |
africanman85: Thank boss Andrenalin: Yeah boss! I hopeful to keep it coming, God's willing. |
Capslock01: 9:52am On Apr 13, 2022 |
Day 6 Create a function that takes 2 inputs: an array of numbers and a target number. Your function should return the indices of the numbers that add up to form the target number. If no two numbers make up the target number, return -1, -1 NB: All numbers in the array can only be used once to add up to the target. NB2: The indices should be returned in an array For example: [1,9,4,5,3, 0] , 10 => Your function => [0,1] [2,5,9,6,1,53, 45], 47 => Your function => [0,6] [4,9,3,5,0,14,10], 100 => Your function => [-1, -1] |
Capslock01: 10:10am On Apr 13, 2022 |
Capslock01: // Day 6 Solution //Return index that form targeted number function takeTwoInputs (arrayOfNumbers, targetNumber) { let found = []; let result = []; for (let value of arrayOfNumbers) { if (found[targetNumber - value] === true) { result.push(arrayOfNumbers.indexOf(targetNumber - value), arrayOfNumbers.indexOf(value)); } found[value] = true; } console.log(result) } takeTwoInputs([1,9,4,5,3,0], 10) takeTwoInputs([2,5,9,6,1,53,45],47) takeTwoInputs([4,9,3,5,0,14,10],100) PS: might modify this code again later. The output when no two numbers make the target number returned empty Array and not array with elements "-1,-1" |
LikeAking: 11:28pm On Apr 13, 2022 |
Capslock01: Nice! All this stuffs na d question just dey confusing. Now I gt the question, find the index position of two numbers in the array that will add up to make the target number. U dey try. Good speed! |
LikeAking: 1:18am On Apr 14, 2022 |
![]() |
Capslock01: 9:22am On Apr 14, 2022 |
LikeAking: Thank you boss! Yeah, the questions are mostly confusing sometimes. I sometimes read over and over then sit over it to understand. Like when I first read this particular question. My mind went to mathematics indices until I figured it's plural of index that's being mentioned. Thank you boss! You're always welcome with your contributions 1 Like |
LikeAking: 9:23am On Apr 14, 2022 |
Capslock01: Thanks. |
(1) Reply)
Why Is No One Talking About Networking Here
(Go Up)
Sections: How To . 51 Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or s on Nairaland. |