Simple Function in JavaScript

Level 384 keystrokes

This defines a function that returns a greeting and calls it with 'Alice'.

JavaScript code

// function keyword defines a named function
// name is a parameter that receives the argument
1function greet(name) {
// return sends a value back to the caller
// String concatenation builds the greeting
2 return "Hello, " + name + "!";
3}
// Call the function with argument "Alice"
4console.log(greet("Alice"));

Output

Hello, Alice!
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • "× 6
  • (× 3
  • )× 3
  • ;× 2
  • +× 2
  • ,× 1
  • !× 1
  • .× 1
  • {× 1
  • }× 1

More JavaScript examples at level 3

← JavaScript typing practice