Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Problem solving with javascript

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 :)

Basic Syntax and Concepts:

1. Concatenate strings:

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;
}

2. Sum of numbers:

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)); // 6
Solution
function sumOfNumbers(num1, num2) {
  const sum = num1 + num2;

  return sum;
}

3. Even or odd:

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)); // Odd
Solution
function evenOrOdd(int) {
  if (int % 2 === 0) {
    return "Even";
  } else {
    return "Odd";
  }
}

4. Print Numbers:

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, 5
Solution
function printNums(n) {
  for (let i = 1; i <= n; i++) {
    console.log(i);
  }
}

5. Iterate through an array:

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, orange
Solution
function iterateThroughArray(arr) {
  for (let i = 0; i < arr.length; i++) {
    const element = arr[i];
    console.log(element);
  }
}

6. large number:

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)); // 4
Solution
function findLarge(num1, num2) {
  if (num1 > num2) {
    return num1;
  } else {
    return num2;
  }

  //   return num1 > num2 ? num1 : num2;
}

String Manipulation:

7. Reverse a String:

Create a function to reverse the characters in a string

Solution
// solution here

8. Palindrome Checker:

Write a function that checks if a word is a palindrome (reads the same backward as forward)

Solution
// solution here

9. Longest Word:

Write a function to find the longest word in a sentence

Solution
// solution here

10. Shortest Word:

Write a function to find the shortest word in a sentence.

Solution
// solution here

11. Title Case:

Write a function to convert a string to title case (capitalize the first letter of each word)

Solution
// solution here

12. Anagram Checker:

Create a function that checks if two words are anagrams (contain the same letters)

Solution
// solution here

Array Manipulation

13. Sort an Array:

Write a function to sort an array of numbers in ascending order

Solution
// solution here

14. Check for Element:

Create a function that checks if a specific element exists in an array

Solution
// solution here

15. Average of Numbers:

Find the average of numbers in an array

Solution
// solution here

16. Intersection of Arrays:

Find the common elements between two arrays

Solution
// solution here

17. Remove Specific Element:

Write a function to remove a specific element from an array

Solution
// solution here

Number Manipulation

18. Maximum of Two Numbers:

Write a function to find the maximum of two numbers.

Solution
// solution here

19. Prime Number Checker:

Check if a number is prime (only divisible by 1 and itself)

Solution
// solution here

20. GCD (Greatest Common Divisor):

Find the GCD of two numbers.

Solution
// solution here

21. LCM (Least Common Multiple):

Find the LCM of two numbers.

Solution
// solution here

22. Sum of Digits:

Calculate the sum of the digits of a number.

Solution
// solution here

23. Perfect Number Checker:

Check if a number is a perfect number (sum of its divisors equals itself)

Solution
// solution here

24. Power of a Number:

Calculate the power of a number

Solution
// solution here

25. Square Root:

Calculate the square root of a number

Solution
// solution here

26. Factorial:

Calculate the factorial of a number

Solution
// solution here

27. Fibonacci Sequence:

Generate the Fibonacci sequence up to a given number of terms.

Solution
// solution here

28. Binary to Decimal Converter:

Convert a binary number to a decimal number

Solution
// solution here

29. Roman Numeral Converter:

Convert a number to a Roman numeral.

Solution
// solution here

30. Area of a Circle:

Calculate the area of a circle with a given radius.

Solution
// solution here

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages