-
Notifications
You must be signed in to change notification settings - Fork 0
/
jst2.html
29 lines (27 loc) · 874 Bytes
/
jst2.html
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
<!DOCTYPE html>
<html>
<head>
<title>String Sorter</title>
</head>
<body>
<h1>String Sorter</h1>
<p>Enter a string to sort:</p>
<input type="text" id="inputString">
<button onclick="sortAndDisplay()">Sort</button>
<p>Sorted result:</p>
<p id="sortedResult"></p>
<script>
function sortStringAlphabetically(inputString) {
const charArray = inputString.split('');
charArray.sort();
return charArray.join('');
}
function sortAndDisplay() {
const inputElement = document.getElementById('inputString');
const inputString = inputElement.value;
const sortedResult = sortStringAlphabetically(inputString);
document.getElementById('sortedResult').textContent = sortedResult;
}
</script>
</body>
</html>