• in
InterCourses
CoursesBlogs
0
← Introduction to JavaScript
○What is JavaScript?○Your First JavaScript Code○Data Types○Type Checking
○Declaring Variables○let and const in Practice○Operators○Type Conversion
○Conditionals○Switch Statement○For Loops○While Loop○Break and Continue
●Defining Functions○Arrow Functions○Scope○Closures○Project - Calculator○Function Expressions
○Arrays○Array Mutation Methods○Array Search and Slice○Array Iteration Methods○Multidimensional Arrays○Destructuring○Array Reverse and Sort○Array Fill○Array Find and Includes○Array Flat and FlatMap○Array Reduce, Some, and Every
○Objects○Object Methods and Destructuring○JSON○Math and Date○Date Basics
○02 Template Literals○String Methods○Regular Expressions
○Higher-Order Functions○Callbacks○map, filter, and reduce○Recursion○Project - Data Transform Pipeline
○OOP Introduction○Classes○Inheritance○Encapsulation
○Asynchronous JavaScript○Promises and Async Await○Async API Simulation

Defining Functions

Functions package logic into a reusable block. This lesson keeps the goal small: write one greeting function and prove that it works for two different names.

Example

javascript
function greet(name) {
  return `Hello, ${name}!`;
}

console.log(greet('Alice'));

Your Task

  1. Write a function greet(name) that returns Hello, <name>!.
  2. Display Hello, Alice! | Hello, Bob! in #output by calling the function twice.
Hint 1
1 / 2
HINT 1

Your function should accept a name parameter and return a string.

Loading editor…
READY
intercourses
javascript