Improve the given code below, make sure that the code will require input from the user.  Problem: Write a Javascript function that would accept two numbers and return the swap of two numbers.   const swap = (a,b) => { console.log("Num2"); console.log("The value of a before swapping = ", a); console.log("The value of b before swapping = ", b); let temp; temp = a; //swaps variables a = b; b = temp; console.log("The value of a after swapping = ", a); console.log("The value of b after swapping = ", b); console.log("\n"); } swap(7,8);

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 14PE
icon
Related questions
Question

Improve the given code below, make sure that the code will require input from the user. 
Problem: Write a Javascript function that would accept two numbers and return the swap of two numbers.

 

const swap = (a,b) => {
console.log("Num2");
console.log("The value of a before swapping = ", a);
console.log("The value of b before swapping = ", b);

let temp;
temp = a; //swaps variables
a = b;
b = temp;

console.log("The value of a after swapping = ", a);
console.log("The value of b after swapping = ", b);
console.log("\n");
}
swap(7,8);

 

Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning