Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
March 16, 2021 04:58 pm GMT

JavaScript Exercises - Conditional Statements

Introduction

When you start by learning JavaScript programming basics, it can be quite hard to think of stuff to do to practice your code knowledge skills. Well, don't worry.

I am going to give you a few coding exercises to practice your code skills. They won't be as hard for some of you, but for those that are only just starting to get into coding, these exercises will be super helpful. They will mainly consist of logical thinking and math solving. The point of this is to focus on the instructions that are given to you and following them.

These tasks are going to be about conditional statements. You can think of this as your level one tasks.

If you enjoy these tasks and want me to make some more levels, let me know so that I can bring them to you.

Task #1 - Speed Test

You need to write a function that receives an argument. This argument is going to be our speed. If our speed meets a certain condition, it should return a certain string.

  • If our speed is under 10 or equal - return slow
  • If our speed is over 10 and up to 40 - return average
  • If our speed is over 40 and is up to 100 - return fast
  • If our speed is over 100 and up to 180 - return very fast
  • If our speed is over 180 - return extremely fast

Here is how the output should look like:

Example 1<------------------------------>speed(30)       //Inputaverage         //OutputExample 2<------------------------------>speed(97)       //Inputfast            //OutputExample 3<------------------------------>speed(180)       //Inputvery fast        //Output

Task #2 - Bonus Score

You will be given one number - your score. This score will get some bonus points if some conditions are met. You have to write a function which counts all the bonus points which this score gets and return the new score (your score + bonus points)

  • If the score is under 100 or equal, the bonus points are 10.
  • If the score is over 100, the bonus points are 30% from the score.
  • If the score is over 1000, the bonus points are 20% from the score.

The extra bonus points(added after the previous bonus point are already applied):

  • If the score is even, you get +4 bonus points.
  • If the score ends on a 5, you get +5 bonus points.

You need to return the number of the bonus points and the new score. Here are some examples of how the output should look like:

Example 1<------------------------------>score(30);  // Original Score14          // Bonus Points44          // New ScoreExample 2<------------------------------>score(3343) //Original Score668.6      //Bonus Points4011.6     //New Score

Task #3 - Time + 25

In this task, you have to write a function, which receives an array as an argument with two string numbers in it. The first number is the hours, and the second is the minutes. Our time will be in the 24-hour time clock. Our function will calculate what the time will be in 25 minutes.

You have to make the strings into numbers. Your output for the hours should always be between 0-23 and your minutes should always be between 0-59. Your minutes should always be with two digits. This means that in some cases it should start with a 0.

In

Here are some examples of how your output should look like:

Example 1<------------------------------>time(['16', '15'])  //Input16:40               //OutputExample 2<------------------------------>time(['3', '58'])   //Input4:23                //OutputExample 3<------------------------------>time(['23', '52'])  //Input0:17                //Output

Conclusion

These are the little fun exercises to practice your if statement skill. If you have any feedback or you need some help, be sure to comment down below. I'd be happy to chat and help! I hope you liked it and if you want me to do some more of these let me know.


Original Link: https://dev.to/boiliev/javascript-exercises-conditional-statements-1jle

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To