We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d650b3c commit 7a8dc7eCopy full SHA for 7a8dc7e
solutions/ch_15_Swap_Numbers/answer2.js
@@ -0,0 +1,10 @@
1
+// Declare a function swap that takes num_1 and num_2 as parameters.
2
+function swap(num_1, num_2) {
3
+ // At first print the numbers before swaping
4
+ console.log("Before swapping:\n num_1 = " + num_1 + "\n num_2 = " + num_2);
5
+ num_1 = num_1 + num_2;
6
+ num_2 = num_1 - num_2;
7
+ num_1 = num_1 - num_2;
8
+ // Check the result by printing the output
9
+ console.log("After swapping:\n num_1 = " + num_1 + "\n num_2 = " + num_2);
10
+}
0 commit comments