Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Using Functions | Functions
New Script JS
course content

Conteúdo do Curso

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.
Tarefa

Swipe to start coding

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 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.
Tarefa

Swipe to start coding

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 1
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt