मुख्य कंटेंट तक स्किप करें

JavaScript tasks

Theory is good, but without practice how to fly with one wing, so in this section we will solve problems in JavaScript. We took the tasks from the Codewars - site this is a site where you can improve your skills not only in JavaScript, but also in other programming languages.

Find numbers that are divisible by a given number

Complete a function that takes two arguments and returns all numbers that are divisible by the given divisor. The first argument is an array of numbers and the second is a divisor.

Example

divisibleBy([1, 2, 3, 4, 5, 6], 2) == [2, 4, 6]

Practice

लाइव एडिटर
परिणाम
Loading...

Answer

See the answer only if you could not solve the problem yourself.

Twice as old

Your function takes two arguments:

  • father's current age (years)
  • the current age of the son (years)

Calculate how many years ago a father was twice as old as his son, or in how many years he will be twice as old.

Practice

लाइव एडिटर
परिणाम
Loading...

Answer

Count odd numbers below n

If number n is given, return the number of positive odd numbers less than n, EASY!

Example

oddCount(7) //=> 3, i.e [1, 3, 5]
oddCount(15) //=> 7, i.e [1, 3, 5, 7, 9, 11, 13]

Practice

लाइव एडिटर
परिणाम
Loading...

Answer

Convert string to number!

We need a function that can convert a string to a number. What ways do you know to achieve this?

Note: Don't worry, all inputs will be strings, and each string is a perfectly valid integer representation.

Example

stringToNumber('1234') == 1234
stringToNumber('605') == 605
stringToNumber('1405') == 1405
stringToNumber('-7') == -7

Practice

लाइव एडिटर
परिणाम
Loading...

Answer

Total

The entire video playlist on this topic can be viewed on our YouTube channel.

On the tatami at Codewars, put on a kimono.

JavaScript is now your main link!