The Word Swapper

Medium+20 XP

Mission Briefing

A sabotage attempt has injected the word "Bad" into the Royal Decree! You must act quickly as the official Word Swapper to fix the document before it reaches the public.

The Concept: String Manipulation

The .replace(target, replacement) method finds the first occurrence of a specific string and replaces it with a new one. Example: "I am sleepy".replace("sleepy", "awake"); // Returns "I am awake"

The Objective

Your function receives a sentence string.

  1. Find the exact word "Bad" (case-sensitive) and replace it with "Good".
  2. Return the modified sentence. (Note: You only need to replace the first occurrence!)

01EXAMPLE 1

Inputsentence = "This is a Bad idea"
Output"This is a Good idea"

Constraints

  • Return the modified string.
CoreStrings
JavaScript
Loading...
3 Hidden

Input Arguments

sentence"The Bad news"

Expected Output

The Good news

Click RUN to test your solution