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

Kursinhalt

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

Swipe to start coding

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 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.
Aufgabe

Swipe to start coding

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 1
Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
We're sorry to hear that something went wrong. What happened?
some-alt