Search⌘ K
AI Features

Exercise: Juggling Values

Explore how to swap values among three variables using JavaScript's variable mutation concepts. This exercise strengthens your understanding of variables and prepares you for challenges in handling value assignments effectively.

We'll cover the following...

Task

Due to unforeseen circumstances, some values of variables have been shifted into one another. Your task: to fix this using your newly acquired knowledge of variable mutation.

Problem statement

You are given three variables named var1, var2 and var3. Write code such that the following is satisfied:

  • var1 contains the value of var2
  • var2 contains the value of var3
  • var3 contains the value of var1

The above diagram illustrates this perfectly. Keeping the above problem in mind, complete the following code. Whenever you feel that you have done it, hit TEST. Good luck!

Code now

Javascript (babel-node)
// update the code below such that the final values of
// the variables are as follows
// var1 contains the value of var2
// var2 contains the value of var3
// var 3 contains the value of var1
var1=var1;
var2=var2;
var3=var3;

NOTE: You can always call in console.log() for debugging purposes. All the print statements from console.log() are in the “Show Console” tab after hitting TEST.