Skip to main content
🌱 Programming for Complete Beginners

Using an Input

Last time your machine always gave the same answer. Now let's let it accept something from the outside β€” an input.

The input goes in the parentheses ( ). We give it a name so we can talk about it. Here a machine takes a name and builds a hello message:

function hello(name) {
  return "Hello, " + name;
}

The little + glues two pieces of text together. So hello("Sam") returns "Hello, Sam". Notice the space after the comma inside the quotes β€” that keeps the words from squishing together. πŸ™‚

Your task

Write a function greet that takes name and returns "Hi, " followed by the name. So greet("Ada") should give back "Hi, Ada".

⚑ 18 XP

🧱 Code blocks

Drag a block into the editor, or tap it to drop it in where your cursor is. Add them in order to build your answer.

solution.jsRuns in your browser
Loading editor…
Tests2 to pass
greet("Ada") gives "Hi, Ada"
greet("Sam") gives "Hi, Sam"

Run your code to check these.