BananaMaster

41 - What is a function and how to use arguments (JS lessons)

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

Task 1.

Create a function that takes 1 argument and prints it to console.log.

Call the function 3 times with different values.

Task 2.

Create a function that takes a number as an argument.

If the number is greater than 10 — print Big to the console, otherwise print Small.

Call the function several times with different numbers.

Task 3.

Create a function that takes a number as an argument.

The function should print to the console all numbers from 1 to the passed number.

Use a for loop.

Task 4.

Create a function that takes a name as an argument.

If the name is Alex, print to the console Hello, Alex!.

If the name is Robert, print to the console Hello, Robert!.

Task 5.

Create a function that takes an animal as an argument.

If cat is passed, print Meow.

If dog — print Woof.

For any other animal print I don't know this animal.

Task 6.

Create a function that takes an age as an argument.

If the age is less than 18 — print Access denied.

Otherwise print Access granted.

Call the function several times with different ages.

Task 7.

Create a function that takes a password as an argument.

If the password equals banana, print Access granted.

Otherwise print Wrong password.

Task 8.

Create a function that takes a number as an argument.

The function should print to the console a countdown from the passed number down to 1.

Use a for loop.

Task 9.

Create a function that takes a number as an argument.

If the number is greater than 100 — print Too big.

If the number is less than 10 — print Too small.

Otherwise print Normal.

Call the function several times with different numbers.

Task 10.

A small task to remember what value is on a <select>.

Create a <select> with animals.

The function is called when a value is selected in the <select>. It takes the selected animal and prints the sound it makes.

This task is solved without using arguments.