Select Page

## JavaScript Challenge Internship to CEO #17/54

Calculate the sum of digits of a positive integer number.

The integer 1235321

## Explanation

The solution is pretty straightforward. You need to separate the digits to loop over them and add them to a sum.

You can do it by a conversion to a string because this is nothing more than a char array under the hood.

You can take advantage of this knowledge by iterating over the array with a for-of-loop. While looping you add up the sum and finally returning the sum to the caller.

This is the printout after the sum was created.

Pro-Tip: If you want to write better code, try to accomplish this task with the reduce() and map() functions from the Array.prototype.

## 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 My Most Read Article with over 8000 Views

One Reason Not to Migrate From JavaScript to TypeScript

Typescript saves a lot of development time, but is it worth an entire migrating process?

Upgrade Your Legacy Coding Style With These 6 Modern Ways of Coding

And How These 3 Famous TV Shows Make You Write Excellent JavaScript Code

## JavaScript Challenge Internship to CEO #16/54

Create a function that will return a Boolean specifying if a number is prime.

Test with 1,5,6,7,9,11,13 & 27.

## Explanation

What is a prime number in maths?

Prime numbers are special numbers, greater than 1, that have exactly two factors, themselves and 1. 19 is a prime number. It can only be divided by 1 and 19. 9 is not a prime number.

In our solution, we first check if the passed number is below 2. Then we already checked against any number below 2 being no prime number.

If the number is equal to 2, then it is a prime number and we can return true.

If any number passed both checks and we are still inside our function, then we find the maximum divisor by getting the square root of our passed number.

With a for loop, we check if the number is remainderless dividable by the iterator of i. If the remainder is 0, then we have definitely another valid calculation instead of only being able to divide a number with 1 and itself to be a prime number. Therefore, we are returning false.

Testifying the given numbers results into this printout.

## 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 My Most Read Article with over 8000 Views

One Reason Not to Migrate From JavaScript to TypeScript

Typescript saves a lot of development time, but is it worth an entire migrating process?

Upgrade Your Legacy Coding Style With These 6 Modern Ways of Coding

And How These 3 Famous TV Shows Make You Write Excellent JavaScript Code

## JavaScript Challenge Internship to CEO #10

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

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

## JavaScript Challenge Internship to CEO #09

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

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

## JavaScript Challenge Internship to CEO #08

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

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

## JavaScript Challenge Internship to CEO #02

Print the odd numbers below than 99 with a `for-loop` .

## Explanation #01

To get the expected result, we start the running index `i` with the value of 1 and have in mind that in between every odd number comes an even number. Therefore, we increase our running index `i` by 2 every iteration with `i += 2`.

We set the condition to `<=99` because we only want to print out odd numbers below 99, i.e. the odd numbers between 1 to 97.

Inside the loop we got our statement of `console.log(i);` which prints out, whatever is inside the brace, to the console window. In our case the wanted odd number.

## Explanation #02

When starting from 97, which is an odd number respectively, and iterate backwards, we almost got it. To get every odd number, we remember ourselves that in between every odd number comes an even number. Jumping over them by decreasing the running index `i` to get every odd number.

We have to change the conditions for the `for-loop`. First `i` starts at 97, then our condition has to be `i > 0`. Not i` >= 0` , otherwise we would print out the even number 0 (Yes 0 is an even number). The running index gets decreased by 2 after every iteration with `i -= 2.`

Inside the loop we got our statement of `console.log(i);` which prints out, whatever is inside the brace, to the console window. In our case the wanted odd number.

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.