JavaScript Challenge  Internship to CEO #11

JavaScript Challenge Internship to CEO #11

Task of Challenge #11/54

Calculate the average of the numbers in an array of numbers. The array: [2, 5, 17, 81, 9].

Solution

Explanation

How to calculate an average

A calculated „central“ value of a set of numbers.

To calculate it: add up all the numbers, then divide by how many numbers there are.

Example: what is the average of 2, 7 and 9?
Add the numbers: 2 + 7 + 9 = 18
Divide by how many numbers (i.e. we added 3 numbers): 18 ÷ 3 = 6
So the average is 6

(Also called the Arithmetic Mean.)

Accomplishing our Goal

To accomplish our task, we create a function called averageArray() and pass in our array.

We need to get the length of the array for our for-loop. Creating a sum and then dividing by the length gets our average.

Just return the number and print it to the console, and you are done!

Follow me on Instagram and don’t miss the latest Challenge!

https://www.instagram.com/arnold.code/

Become a bullet proof developer and seek my coding adventures on Udemy

https://www.udemy.com/user/arnold-abraham-3/

Don’t miss two of my most read Medium Articles

JavaScript Challenge  Internship to CEO #10

JavaScript Challenge Internship to CEO #10

Task of Challenge #10/54

 Calculate the sum of numbers in an array of numbers. The array: [1, 9, -19, 3, 5, 3, 7, 14, 91].

Solution

Explanation

To accomplish our task, we need to iterate over the array and build the sum out of each element.

Since we aren’t so experienced right now, we should not use the reduce() function. Instead, we write basic operations like this with a for loop

After the loop has finished, we print it out to the console:

Follow me on Instagram and don’t miss the latest Challenge!

https://www.instagram.com/arnold.code/

Become a bullet proof developer and seek my coding adventures on Udemy

https://www.udemy.com/user/arnold-abraham-3/

Don’t miss two of my most read Medium Articles

JavaScript Challenge  Internship to CEO #09

JavaScript Challenge Internship to CEO #09

Task of Challenge #09/54

Create a function that will convert from Fahrenheit to Celsius. Convert -38 degree Fahrenheit.

Solution

Explanation

How to convert Celsius to Fahrenheit

The temperature T in degrees Fahrenheit (°F) is equal to the temperature T in degrees Celsius (°C) times 9/5 plus 32:

T(°F) = T(°C) × 9/5 + 32

or

T(°F) = T(°C) × 1.8 + 32

Example

Convert 20 degrees Celsius to degrees Fahrenheit:

T(°F) = 20°C × 9/5 + 32 = 68 °F

To accomplish our task, we need to reverse the conversion of degrees to Fahrenheit. This means we first subtract 32 and then divide by 1.8.

This is done in the convertFahrenheitToCelsius-function.

Just return the number and print it out, and you are done!

The console prints out -38.888888888888886 when we put in the number -38.

Because this is the point where Celsius and Fahrenheit have the same amount.

Follow me on Instagram and don’t miss the latest Challenge!

https://www.instagram.com/arnold.code/

Become a bullet proof developer and seek my coding adventures on Udemy

https://www.udemy.com/user/arnold-abraham-3/

Don’t miss two of my most read Medium Articles

JavaScript Challenge  Internship to CEO #08

JavaScript Challenge Internship to CEO #08

Task of Challenge #08/54

Create a function that will convert from Celsius to Fahrenheit. Convert 0 degree Celsius.

Solution

Explanation

How to convert Celsius to Fahrenheit

The temperature T in degrees Fahrenheit (°F) is equal to the temperature T in degrees Celsius (°C) times 9/5 plus 32:

T(°F) = T(°C) × 9/5 + 32

or

T(°F) = T(°C) × 1.8 + 32

Example

Convert 20 degrees Celsius to degrees Fahrenheit:

T(°F) = 20°C × 9/5 + 32 = 68 °F

To accomplish our task, we need to return a number calculated with 1.8 and add 32 to it.

This is done in the convertCelsiusToFahrenheit-function.

Just return the number and print it out, and you are done!

The console prints out 32 when we put in the number 0.

Follow me on Instagram and don’t miss the latest Challenge!

https://www.instagram.com/arnold.code/

Become a bullet proof developer and seek my coding adventures on Udemy

https://www.udemy.com/user/arnold-abraham-3/

Don’t miss two of my most read Medium Articles

JavaScript Challenge  Internship to CEO #07

JavaScript Challenge Internship to CEO #07

Task of Challenge #07/54

Calculate the sum of odd numbers greater than 9 and less than 30 a for-loop .

Solution

Explanation

To accomplish our task, we should remember challenge #02 because back then, the task was to print out every odd number below 99. That means we create a for loop with an increment of 2 after each iteration to get only odd numbers when starting with an odd number. In our case with 11.

Remembering challenge #05 makes us also happy again. There we had the task to create the sum of the numbers from 1 to 24. The same concept applies to this task. We add up every odd number above 9 and below 30 to a sum.

After the loop has finished, we print it out to the console:

Accumulated value printed out to the console (Sum of all odd numbers >9 & <30)

Follow me on Instagram and don’t miss the latest Challenge!

https://www.instagram.com/arnold.code/

Gather more Knowledge about JavaScript?

Here are two pre-picked and high quality Medium articles for you.