Variable Swapping
Easy+20 XP
Mission Briefing
Two ancient relics have been placed on the wrong pedestals! You must safely swap their positions without dropping either of them.
The Concept: Swapping Variables
Imagine holding a sword in your right hand and a shield in your left. To swap them, you can't just move them at the same time—you need to place one on a table (a temporary variable) first. In code, a third variable temporarily holds a value so it isn't overwritten.
The Objective
Your function receives parameters a and b.
- Create a temporary variable to hold the value of
a. - Swap the values of
aandb. - Return them as an array
[a, b]in their new positions.
01EXAMPLE 1
Input
a = 5, b = 10Output
[10, 5]02EXAMPLE 2
Input
a = "cat", b = "dog"Output
["dog", "cat"]Constraints
- Return the swapped values as an array [a, b].
FundamentalsLogicVariables
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
a5
b10
Expected Output
[10,5]
Click RUN to test your solution