Code Lab

Function types

EasyTypeScript types3 min

The function greet(name, times) returns a string where the greeting Hi, <name>! is repeated times times, separated by spaces. Add the parameters with types, set the return type and write the function body.

Do not change the code at the bottom. Each line after @ts-expect-error must stay a type error.

Examples

greet('Ann', 2)

Returns 'Hi, Ann! Hi, Ann!'

Two greetings with a space between them.
greet('Bob', 1)

Returns 'Hi, Bob!'

One greeting with no spaces around it.
greet('Ann', 0)

Returns ''

Zero repeats give an empty string.

Source

Function
Loading the editor...
  1. Inputgreet('Ann', 2)
    Expected'Hi, Ann! Hi, Ann!'
  2. Inputgreet('Bob', 1)
    Expected'Hi, Bob!'

Hidden tests run on Submit.