Exchange values

In this exercise you have to write a program that will exchange values between 2 variables. It also mean interchanging the values of 2 variables.

Exchange values : Requirement

Here are the requirements :

  • Accept 2 values from the user and store them in 2 variables eg. var a and var b
  • Interchange the values. Means if you give value 5 to variable ‘a’ and value 10 to variable ‘b’, the output should be variable ‘a’ is 10 and variable ‘b’ is 5

Exchange values : Hints

You will need to make use of the following javascript concepts:

  • Prompt box to accept values
  • Variables to store values
  • A temporary variable to exchange values
  • Alert box to show the output

Planning the logic

You will need to perform the following tasks

  • Get the values from the user
  • Store the values in variables
  • Interchange the values, this is what makes it tricky
  • Display the output message

Find this challenging? Give it a spin.

Trying solving this using any of the online editors and send me an email if you need any help or feedback on your code.