Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Challenge: Write a Function – My Name | Functions in JavaScript
Introduction to JavaScript
course content

Kursinnehåll

Introduction to JavaScript

Introduction to JavaScript

1. JavaScript Fundamentals
2. Variables and Data Types in JavaScript
3. Performing Operations in JavaScript
4. Controlling Program Flow with Conditional Statements
5. Looping Through Data in JavaScript
6. Functions in JavaScript

book
Challenge: Write a Function – My Name

Task

Implement a function to output a sentence:

  1. Name the function myName.
  2. The function should accept one argument, name.
  3. The myName function body should contain a console.log() statement that prints the sentence "My name is {name}".
  4. Call the myName function three times with different names.
1234567
function ___(___) { console.log("My name is", ___); }; myName("___"); myName("___"); myName("___");
copy

The output should be:

python
  1. Function definition: function funcName(argument) {}.
  2. Place the argument name inside the console.log() function.
  3. Call the function with different names (choose them yourself).
  4. Call the funcName function after defining it using the funcName(value) syntax.
1234567
function myName(name) { console.log("My name is", name); } myName("Ashley"); myName("Ervin"); myName("Mabel");
copy

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 6. Kapitel 3
Vi beklagar att något gick fel. Vad hände?
some-alt