# JavaScript | Coding Challenge Set #1 For Beginners

Hello JavaScript code newbie! In this article I’m proposing you a series of JavaScript coding challenge that will help you practice the basic language constructs and algorithms. You can also read our JavaScript | Intro To Job Titles

Note: This blog is for Beginners

Coding Challenge Set #1 For Beginners

These JavaScript challenge are specially designed for beginners, therefore the proposed solutions are implemented using only simple and classical JavaScript programming elements.

If you are not bounded with time limit, we recommend you to solve the challenges on by yourself first before viewing solutions and then compare your solution to the provided solution. If you don’t have enough time to code yourself, just click on “View Code” and analyze the solutions!

## List of JavaScript coding challenge 1 to 26

### 1: Print numbers from 1 to 10 using JavaScript.

Click here to View Code

### 2: Print the odd numbers less than 100 using JavaScript.

Click here to View Code

### 3: Print the multiplication table with 7 using JavaScript.

Click here to View Code

### 4: Print all the multiplication tables with numbers from 1 to 10 using JavaScript.

Click here to View Code

### 5: Calculate the sum of numbers from 1 to 10 using JavaScript.

Click here to View Code

### 6: Calculate 10! (factorial of 10)

Click here to View Code

### 7: Calculate the sum of odd numbers greater than 10 and less than 30 using JavaScript.

Click here to View Code

### 8: Create a function that will convert from Celsius to Fahrenheit using JavaScript.

Click here to View Code

### 9: Create a function that will convert from Fahrenheit to Celsius using JavaScript.

Click here to View Code

### 10: Calculate the sum of numbers in an array of numbers using JavaScript.

Click here to View Code

### 11: Calculate the average of the numbers in an array of numbers using JavaScript.

Click here to View Code

### 12: Create a function that receives an array of numbers and returns an array containing only the positive numbers using JavaScript.

Click here for Solution 1 View Code

Click here for Solution 2 View Code

Click here for Solution 3 View Code

### 13: Find the maximum number in an array of numbers using JavaScript.

Click here to View Code

### 14: Print the first 10 Fibonacci numbers without recursion using JavaScript.

Click here to View Code

### 15: Create a function that will find the nth Fibonacci number using recursion using JavaScript.

Click here to View Code

### 16: Create a function that will return a Boolean specifying if a number is prime using JavaScript.

Click here to View Code

### 17: Calculate the sum of digits of a positive integer number using JavaScript.

Click here to View Code

### 18: Print the first 100 prime numbers using JavaScript.

Click here to View Code

### 19: Create a function that will return in an array the first “nPrimes” prime numbers greater than a particular number “startAt” using JavaScript.

Click here to View Code

### 20: Rotate an array to the left 1 position using JavaScript.

Click here to View Code

### 21: Rotate an array to the right 1 position using JavaScript.

Click here to View Code

### 22: Reverse an array using JavaScript.

Click here to View Code

### 23: Reverse a stringnumber is prime using JavaScript.

Click here to View Code

### 24: Create a function that will merge two arrays and return the result as a new array using JavaScript.

Click here to View Code

### 25: Create a function that will receive two arrays of numbers as arguments and return an array composed of all the numbers that are either in the first array or second array but not in both array, code using JavaScript.

Click here to View Code

### 26: Create a function that will receive two arrays and will return an array with elements that are in the first array but not in the second using JavaScript.

Click here to View Code

Thank you for reading and stay tune, stay connected and stay safe. Please support us by sharing the blog.

Useful blogs JavaScript | Intro To Job Titles

Read our other blogs on ITbulls.in

### Mishan Goti

Mean Stack Developer
"I am a developer with 2+ years of experience in developing web applications and solutions for many domestic and international clients."

Previous Post
Next Post

```                    ```
for(var i = 1; i <= 10; i++)
{
console.log(i);
}
```
```

```                    ```
for(var i = 1; i <= 100; i += 2)
{
console.log(i);
}
```
```

```                    ```
for(var i = 1; i <= 10; i++)
{
var row = "7 * " + i + " = " + 7 * i;
console.log(row);
}
```
```

```                    ```
for(var i = 1; i <= 10; i++)
{
printTable(i);
console.log("");
}

function printTable(n)
{
for(var i = 1; i <= 10; i++)
{
var row = n + " * " + i + " = " + n * i;
console.log(row);
}
}
```
```

```                    ```
var sum = 0;

for(var i = 1; i <= 10; i++)
{
sum += i;
}

console.log(sum);
```
```

```                    ```
var prod = 1;

for(var i = 1; i <= 10; i++)
{
prod *= i;
}

console.log(prod);
```
```

```                    ```
var sum = 0;

for(var i = 11; i < 30; i += 2)
{
sum += i;
}

console.log(sum);
```
```

```                    ```
function celsiusToFahrenheit(n)
{
return n * 1.8 + 32;
}

var r = celsiusToFahrenheit(20);
console.log(r);
```
```

```                    ```
function fahrenheitToCelsius(n)
{
return (n - 32) / 1.8;
}

var r = fahrenheitToCelsius(68);
console.log(r);
```
```

```                    ```
function sumArray(ar)
{
var sum = 0;

for(var i = 0; i < ar.length; i++)
{
sum += ar[i];
}

return sum;
}

var ar = [2, 3, -1, 5, 7, 9, 10, 15, 95];
var sum = sumArray(ar);
console.log(sum);
```
```

```                    ```
function averageArray(ar)
{
var n = ar.length;
var sum = 0;

for(var i = 0; i < n; i++)
{
sum += ar[i];
}

return sum / n;
}

var ar = [1, 3, 9, 15, 90];
var avg = averageArray(ar);

console.log("Average: ", avg);
```
```

```                    ```
function getPositives(ar)
{
var ar2 = [];
for(var i = 0; i < ar.length; i++)
{
var el = ar[i];
if (el >= 0)
{
ar2.push(el);
}
}
return ar2;
}
var ar = [-5, 10, -3, 12, -9, 5, 90, 0, 1];
var ar2 = getPositives(ar);
console.log(ar2);

```
```

```                    ```
function getPositives(ar)
{
var ar2 = [];
for(var el of ar)
{
if (el >= 0)
{
ar2.push(el);
}
}
return ar2;
}
var ar = [-5, 10, -3, 12, -9, 5, 90, 0, 1];
var ar2 = getPositives(ar);
console.log(ar2);
```
```

```                    ```
function getPositives(ar)
{
return ar.filter(el => el >= 0);
}

var ar = [-5, 10, -3, 12, -9, 5, 90, 0, 1];
var ar2 = getPositives(ar);
console.log(ar2);
```
```

```                    ```
function findMax(ar)
{
var max = ar;
for(var i = 0; i < ar.length; i++)
{
if (ar[i] > max)
{
max = ar[i];
}
}
return max;
}
var ar = [-5, 10, -3, 12, -9, 5, 90, 0, 1];
var max = findMax(ar);
console.log("Max: ", max);

```
```

```                    ```
var f0 = 0;
console.log(f0);

var f1 = 1;
console.log(f1);

for(var i = 2; i < 10; i++)
{
var fi = f1 + f0;
console.log(fi);

f0 = f1;
f1 = fi;
}

```
```

```                    ```
function findFibonacci(n)
{
if (n == 0)
return 0;

if (n == 1)
return 1;

return findFibonacci(n - 1) + findFibonacci(n - 2);
}

var n = findFibonacci(10);
console.log(n);

```
```

```                    ```
function isPrime(n)
{
if (n < 2)
return false;

if (n == 2)
return true;

var maxDiv = Math.sqrt(n);

for(var i = 2; i <= maxDiv; i++)
{
if (n % i == 0)
{
return false;
}
}

return true;
}

console.log(2, " is prime? ", isPrime(2));
console.log(3, " is prime? ", isPrime(3));
console.log(4, " is prime? ", isPrime(4));
console.log(5, " is prime? ", isPrime(5));
console.log(9, " is prime? ", isPrime(9));

```
```

```                    ```
function sumDigits(n)
{
var s = n.toString();
var sum = 0;

for(var char of s)
{
var digit = parseInt(char);
sum += digit;
}

return sum;
}

var sum = sumDigits(1235231);
console.log("Sum: ", sum);

```
```

```                    ```
printPrimes(100);

// Function prints the first nPrimes numbers
function printPrimes(nPrimes)
{
var n = 0;
var i = 2;

while(n < nPrimes)
{
if (isPrime(i))
{
console.log(n, " --> ", i);
n++;
}

i++;
}
}

// Returns true if a number is prime
function isPrime(n)
{
if (n < 2)
return false;

if (n == 2)
return true;

var maxDiv = Math.sqrt(n);

for(var i = 2; i <= maxDiv; i++)
{
if (n % i == 0)
{
return false;
}
}

return true;
}

```
```

```                    ```
console.log(getPrimes(10, 100));

function getPrimes(nPrimes, startAt)
{
var ar = [];

var i = startAt;

while(ar.length < nPrimes)
{
if (isPrime(i))
{
ar.push(i);
}

i++;
}

return ar;
}

// Returns true if a number is prime
function isPrime(n)
{
if (n < 2)
return false;

if (n == 2)
return true;

var maxDiv = Math.sqrt(n);

for(var i = 2; i <= maxDiv; i++)
{
if (n % i == 0)
{
return false;
}
}

return true;
}

```
```

```                    ```
var ar = [1, 2, 3];
rotateLeft(ar);
console.log(ar);

function rotateLeft(ar)
{
var first = ar.shift();
ar.push(first);
}

```
```

```                    ```
var ar = [1, 2, 3];
rotateRight(ar);
console.log(ar);

function rotateRight(ar)
{
var last = ar.pop();
ar.unshift(last);
}

```
```

```                    ```
var ar = [1, 2, 3];
var ar2 = reverseArray(ar);
console.log(ar2);

function reverseArray(ar)
{
var ar2 = [];

for(var i = ar.length - 1; i >= 0; i--)
{
ar2.push(ar[i]);
}

return ar2;
}

```
```

```                    ```
var s = reverseString("JavaScript");
console.log(s);

function reverseString(s)
{
var s2 = "";

for(var i = s.length - 1; i >= 0; i--)
{
var char = s[i];
s2 += char;
}

return s2;
}

```
```

```                    ```
function sumDigits(n)
{
var s = n.toString();
var sum = 0;

for(var char of s)
{
var digit = parseInt(char);
sum += digit;
}

return sum;
}

var sum = sumDigits(1235231);
console.log("Sum: ", sum);

```
```

```                    ```
var ar1 = [1, 2, 3, 10, 5, 3, 14];
var ar2 = [1, 4, 5, 6, 14];

var ar = mergeExclusive(ar1, ar2);
console.log(ar);

function mergeExclusive(ar1, ar2)
{
var ar = [];

for(let el of ar1)
{
if (!ar2.includes(el))
{
ar.push(el);
}
}

for(let el of ar2)
{
if (!ar1.includes(el))
{
ar.push(el);
}
}

return ar;
}

```
```

```                    ```
var ar1 = [1, 2, 3, 10, 5, 3, 14];
var ar2 = [-1, 4, 5, 6, 14];

var ar = mergeLeft(ar1, ar2);
console.log(ar);

function mergeLeft(ar1, ar2)
{
var ar = [];

for(let el of ar1)
{
if (!ar2.includes(el))
{
ar.push(el);
}
}

return ar;
}

```
```