Skip to content

Task 2 - Return Hello ${name}! #2

Description

@pivee

You need to create a function that returns "Hello Kasun!" if the parameter that had been passed was "Kasun". If no parameters were passed, it should return "Hello World!". If the parameters that were passed were invalid, it should throw an error.

There are several methods you can use:

  • You can use backticks (`) to create template literals to simplify string concatenation.
  • You can use Array.prototype.join() to make it a bit more complex.

There's a design principle called KISS: Keep It Simple, Stupid.

KISS: Keep It Simple, Stupid
Designs and/or systems should be as simple as possible. Wherever possible, complexity should be avoided in a system—as simplicity guarantees the greatest levels of user acceptance and interaction.

Example:

function getHello(name) {
  if (name === undefined) {
    return "Hello World!";
  } else if (typeof name === "string") {
    return `Hello ${name}!`;
  } else {
    throw new Error("Invalid name.");
  }
}

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions