-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswap2no.html
More file actions
47 lines (36 loc) · 1.07 KB
/
Copy pathswap2no.html
File metadata and controls
47 lines (36 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html>
<head>
<title>Swap Two Values</title>
</head>
<body>
<h2>Swap Two Values</h2>
<form>
<label>Enter first value:</label><br>
<input type="text" id="a" placeholder="Enter value A"><br><br>
<label>Enter second value:</label><br>
<input type="text" id="b" placeholder="Enter value B"><br><br>
<input type="button" value="Swap" onclick="swapValues()">
</form>
<p id="result"></p>
<script>
function swap(a, b) {
let temp = a;
a = b;
b = temp;
return [a, b];
}
function swapValues() {
let a = document.getElementById("a").value;
let b = document.getElementById("b").value;
if (a === "" || b === "") {
document.getElementById("result").innerHTML = "Please enter both values.";
return;
}
let swapped = swap(a, b);
document.getElementById("result").innerHTML =
"After swapping:<br>Value A = " + swapped[0] + "<br>Value B = " + swapped[1];
}
</script>
</body>
</html>