Questions for the Challenges: Below is the complete list of all challenges:
Possible Solutions: You can find the corresponding solutions linked below each question.
Have fun practicing JavaScript and coding by solving enjoyable beginner-friendly exercises. These exercises are designed for people who are new to programming and those who have reached an intermediate level. If you're just starting out in programming, begin with these challenges. By working on them, you'll become a skilled programmer in a short time.
If programming is entirely new to you, it's a good idea to grasp some programming basics from the recommended resources. Once you've got the basics down, you can start tackling these problems. Remember to keep learning, solving problems, and working on projects as you continue your programming journey.
The challenges range from very easy to intermediate difficulty, and there are even a few semi-advanced problems. If you're unable to solve a problem on your own, you can take a look at my solution or seek assistance elsewhere. Then, give it another shot on your own. Enjoy the process of coding :)
Create a function that takes two strings as arguments and return a new string.
function concatinateStrings(str1, str2) {
// Your code
}
console.log(concatinateStrings("Hello", "World!")); // Hello, World!
console.log(concatinateStrings("Hello", "Sam!")); // Hello, Sam!Solution
function concatinateStrings(str1, str2) {
const result = str1 + " " + str2;
const result2 = `${str1} ${str2}`;
return result2;
}Create a simple function that takes two numbers as arguments and returns the sum of two numbers.
function sumOfNumbers(num1, num2) {
// Your code
}
console.log(sumOfNumbers(1, 2)); // 3
console.log(sumOfNumbers(3, 3)); // 6Solution
function sumOfNumbers(num1, num2) {
const sum = num1 + num2;
return sum;
}Create a function that takes an integer as an argument and returns "Even" for even numbers or "Odd" for odd numbers.
function evenOrOdd(int) {
// Your code
}
console.log(evenOrOdd(2)); // Even
console.log(evenOrOdd(3)); // OddSolution
function evenOrOdd(int) {
if (int % 2 === 0) {
return "Even";
} else {
return "Odd";
}
}Create a function that takes an integer as an argument and it prints all the numbers starting from 1 upto the given number.
function printNums(n) {
// Your code
}
console.log(printNums(3)); // 1, 2, 3
console.log(printNums(5)); // 1, 2, 3, 4, 5Solution
function printNums(n) {
for (let i = 1; i <= n; i++) {
console.log(i);
}
}Iterate through an array using a loop and print each element.
function iterateThroughArray(arr) {
// Your code
}
console.log(iterateThroughArray([1, 2, 3])); // 1, 2, 3
console.log(iterateThroughArray(["apple", "bannana", "orange"])); // apple, banana, orangeSolution
function iterateThroughArray(arr) {
for (let i = 0; i < arr.length; i++) {
const element = arr[i];
console.log(element);
}
}Create a function that takes two parameters and returns the larger one.
function findLarge(num1, num2) {
// Your code
}
console.log(findLarge(1, 2)); // 2
console.log(findLarge(4, 3)); // 4Solution
function findLarge(num1, num2) {
if (num1 > num2) {
return num1;
} else {
return num2;
}
// return num1 > num2 ? num1 : num2;
}Create a function to reverse the characters in a string
Solution
// solution hereWrite a function that checks if a word is a palindrome (reads the same backward as forward)
Solution
// solution hereWrite a function to find the longest word in a sentence
Solution
// solution hereWrite a function to find the shortest word in a sentence.
Solution
// solution hereWrite a function to convert a string to title case (capitalize the first letter of each word)
Solution
// solution hereCreate a function that checks if two words are anagrams (contain the same letters)
Solution
// solution hereWrite a function to sort an array of numbers in ascending order
Solution
// solution hereCreate a function that checks if a specific element exists in an array
Solution
// solution hereFind the average of numbers in an array
Solution
// solution hereFind the common elements between two arrays
Solution
// solution hereWrite a function to remove a specific element from an array
Solution
// solution hereWrite a function to find the maximum of two numbers.
Solution
// solution hereCheck if a number is prime (only divisible by 1 and itself)
Solution
// solution hereFind the GCD of two numbers.
Solution
// solution hereFind the LCM of two numbers.
Solution
// solution hereCalculate the sum of the digits of a number.
Solution
// solution hereCheck if a number is a perfect number (sum of its divisors equals itself)
Solution
// solution hereCalculate the power of a number
Solution
// solution hereCalculate the square root of a number
Solution
// solution hereCalculate the factorial of a number
Solution
// solution hereGenerate the Fibonacci sequence up to a given number of terms.
Solution
// solution hereConvert a binary number to a decimal number
Solution
// solution hereConvert a number to a Roman numeral.
Solution
// solution hereCalculate the area of a circle with a given radius.
Solution
// solution here