This content originally appeared on DEV Community and was authored by bo-iliev
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) //Input
average //Output
Example 2
<------------------------------>
speed(97) //Input
fast //Output
Example 3
<------------------------------>
speed(180) //Input
very 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 Score
14 // Bonus Points
44 // New Score
Example 2
<------------------------------>
score(3343) //Original Score
668.6 //Bonus Points
4011.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']) //Input
16:40 //Output
Example 2
<------------------------------>
time(['3', '58']) //Input
4:23 //Output
Example 3
<------------------------------>
time(['23', '52']) //Input
0: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.
This content originally appeared on DEV Community and was authored by bo-iliev
bo-iliev | Sciencx (2021-03-16T16:58:50+00:00) JavaScript Exercises – Conditional Statements. Retrieved from https://www.scien.cx/2021/03/16/javascript-exercises-conditional-statements/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.