Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Using Functions | Functions
New Script JS
course content

Зміст курсу

New Script JS

New Script JS

1. Basic Controls
2. Functions
3. Loops
4. If-Else Statements
5. Challenges

book
Using Functions

Why Use Functions?

Repeating code makes programs long and hard to maintain. Functions let you group commands into a reusable block, reducing repetition and making your code cleaner.

How to call Functions?

To call a function, simply use its name followed by parentheses, placing any required arguments inside those parentheses.

In the example below, the greet function is called on line 5 by adding parentheses to its name and passing "Alice" as the name argument.

A Simple Function Example

12345
function greet(name) { console.log("Hello, " + name + "!"); } greet("Alice");
copy

Here’s what happens when you call greet("Alice"):

  1. JavaScript looks for the function named greet.
  2. It passes the string "Alice" as the argument for the parameter name.
  3. Inside the function, the console.log statement concatenates "Hello, ", the value "Alice", and "!" to create the full greeting.
  4. The final message "Hello, Alice!" is then printed to the console.
Завдання

Swipe to start coding

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 1
js

ninja.js

html

index.html

js

preset.js

toggle bottom row

book
Using Functions

Why Use Functions?

Repeating code makes programs long and hard to maintain. Functions let you group commands into a reusable block, reducing repetition and making your code cleaner.

How to call Functions?

To call a function, simply use its name followed by parentheses, placing any required arguments inside those parentheses.

In the example below, the greet function is called on line 5 by adding parentheses to its name and passing "Alice" as the name argument.

A Simple Function Example

12345
function greet(name) { console.log("Hello, " + name + "!"); } greet("Alice");
copy

Here’s what happens when you call greet("Alice"):

  1. JavaScript looks for the function named greet.
  2. It passes the string "Alice" as the argument for the parameter name.
  3. Inside the function, the console.log statement concatenates "Hello, ", the value "Alice", and "!" to create the full greeting.
  4. The final message "Hello, Alice!" is then printed to the console.
Завдання

Swipe to start coding

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 1
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt