Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,159,342 members, 7,839,608 topics. Date: Saturday, 25 May 2024 at 01:47 AM

Dairy Of Javascript Challenge - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Dairy Of Javascript Challenge (1883 Views)

Who Has The Complete Version Of Javascript By Tutorials Point? / What are the Advantages Of Javascript Framework Over Vanilla Javascript / 30 Days Of Javascript Challenge {June 21 - July 20} (2) (3) (4)

(1) (2) (Reply) (Go Down)

Dairy Of Javascript Challenge by Capslock01: 11:34am On Apr 11, 2022
Hi all,

I'd be documenting the 30 days challenge of JavaScript I just joined, though the challenge is now at day 7 but it's never late.

PS: I'm just way below average JavaScript user 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.
Re: Dairy Of Javascript Challenge by 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;
Re: Dairy Of Javascript Challenge by Capslock01: 11:40am On Apr 11, 2022
Capslock01:
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;

// 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

Re: Dairy Of Javascript Challenge by 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
Re: Dairy Of Javascript Challenge by Capslock01: 12:15pm On Apr 11, 2022
Capslock01:
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

// 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)
Re: Dairy Of Javascript Challenge by Deicide: 2:30pm On Apr 11, 2022
Capslock01:
Hi all,

I'd be documenting the 30 days challenge of JavaScript I just joined, though the challenge is now at day 7 but it's never late.

PS: I'm just way below average JavaScript user 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.
Are you new to JavaScript?
Re: Dairy Of Javascript Challenge by Capslock01: 4:07pm On Apr 11, 2022
Deicide:
Are you new to JavaScript?

Kind of.
But;
I've got knowledge of how things work.
As I've done some basic projects with it though.
Re: Dairy Of Javascript Challenge by LikeAking: 4:17pm On Apr 11, 2022
Capslock01:


Kind of.
But;
I've got knowledge of how things work.
As I've done some basic projects with it though.

I hope u ar not copying ans from d web, some spying things.

Any way you are doing good.
Re: Dairy Of Javascript Challenge by Deicide: 4:20pm On Apr 11, 2022
Capslock01:


Kind of.
But;
I've got knowledge of how things work.
As I've done some basic projects with it though.
I was just wondering why you didn't use the reduce function for the Array sum

1 Like 1 Share

Re: Dairy Of Javascript Challenge by Capslock01: 5:29pm On Apr 11, 2022
LikeAking:


I hope u ar not copying ans from d web, some spying things.

Any way you are doing good.



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.
Re: Dairy Of Javascript Challenge by Capslock01: 5:38pm On Apr 11, 2022
Deicide:
I was just wondering why you didn't use the reduce function for the Array sum

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.
Re: Dairy Of Javascript Challenge by 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.
Re: Dairy Of Javascript Challenge by Biggerbros234: 6:38pm On Apr 11, 2022
qtguru:
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.
Hi qtguru.
What do you think about zapier and Zoho on upwork?
Re: Dairy Of Javascript Challenge by qtguru(m): 6:50pm On Apr 11, 2022
Biggerbros234:

Hi qtguru.
What do you think about zapier and Zoho on upwork?

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.
Re: Dairy Of Javascript Challenge by Capslock01: 10:59pm On Apr 11, 2022
qtguru:
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.

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.
Re: Dairy Of Javascript Challenge by 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]]
Re: Dairy Of Javascript Challenge by Capslock01: 11:12pm On Apr 11, 2022
Capslock01:
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]]


// 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
Re: Dairy Of Javascript Challenge by 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’]
Re: Dairy Of Javascript Challenge by Capslock01: 9:47am On Apr 12, 2022
Capslock01:
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’]


// 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);
Re: Dairy Of Javascript Challenge by 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

Re: Dairy Of Javascript Challenge by Capslock01: 4:18pm On Apr 12, 2022
Capslock01:
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’}]


// 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

Re: Dairy Of Javascript Challenge by LikeAking: 5:40pm 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']);

Clapps!!!!!!!!!!!
Re: Dairy Of Javascript Challenge by Capslock01: 9:01pm On Apr 12, 2022
LikeAking:


Clapps!!!!!!!!!!!

Wawwwu! Thank boss.
Re: Dairy Of Javascript Challenge by africanman85: 4:06am On Apr 13, 2022
Nice
Re: Dairy Of Javascript Challenge by Andrenalin: 7:36am On Apr 13, 2022
i love this lets keep it going...
Re: Dairy Of Javascript Challenge by Capslock01: 9:49am On Apr 13, 2022
africanman85:
Nice

Thank boss

Andrenalin:
i love this lets keep it going...

Yeah boss! I hopeful to keep it coming, God's willing.
Re: Dairy Of Javascript Challenge by 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]
Re: Dairy Of Javascript Challenge by Capslock01: 10:10am On Apr 13, 2022
Capslock01:
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]

// 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"
Re: Dairy Of Javascript Challenge by LikeAking: 11:28pm 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"

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!
Re: Dairy Of Javascript Challenge by LikeAking: 1:18am On Apr 14, 2022
smiley
Re: Dairy Of Javascript Challenge by Capslock01: 9:22am On Apr 14, 2022
LikeAking:


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!

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

Re: Dairy Of Javascript Challenge by LikeAking: 9:23am On Apr 14, 2022
Capslock01:


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

Thanks.

(1) (2) (Reply)

Here Are Some Of My Folders, Jealous? / Microsoft Programming Competition: Nigerian Students To Travel To Usa In July / Data Scientist Only

(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. 57
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.