BananaMaster

44 - What is return and why do we need it (JS lessons)

If you forgot something — click to go to the lesson.

Task 1.

Write a function checkAge that takes an age.

Inside, determine whether the person is an adult (18 years old and above). The result of this action is true or false.

This result needs to be obtained in the outer scope for ages 15 and 20.

Task 2.

Write a function sumRange that takes a number (a limit).

Inside, using a for loop, calculate the sum of all numbers from 1 to this number. The result of this action is a number.

Get this number in the outer scope.

Task 3.

Write a function findMax that takes 3 numbers.

Inside, determine on your own which of the three numbers is the largest. The result of this action is a number.

Get this number in the outer scope.

Task 4.

Write a function getGrade that takes a grade (a number from 0 to 100).

Come up with your own conditions: if the grade is 90 and above — 'A', from 70 to 89 — 'B', otherwise — 'C'. The result of this action is a letter.

Get this letter in the outer scope.

Task 5.

Write a function calculateBonus that takes a salary and years of experience.

Come up with your own conditions for the bonus: if the experience is 5 years or more — 20% of the salary, if from 2 to 4 years — 10%, otherwise — no bonus. The result of this action is the bonus amount.

Get this amount in the outer scope.

Task 6.

Write a function validatePassword that takes a password (a string).

Come up with your own check: a password is considered valid if it is not shorter than 8 characters and contains at least one uppercase letter. The result of this action is true or false.

Get this result in the outer scope.

Task 7.

Write a function checkTicketPrice that takes an age and a day of the week (a string, for example 'Monday').

The base ticket price is 10 dollars. If the age is less than 12 or 65 and above — the price is 5 dollars. If the day of the week is 'Monday', 'Tuesday' or 'Wednesday' — additionally subtract 2 dollars from the final price.

Get the final price in the outer scope.