-
Notifications
You must be signed in to change notification settings - Fork 0
/
task8.html
35 lines (30 loc) · 1.13 KB
/
task8.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
30
31
32
33
34
35
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Javascript - Task 2</title>
</head>
<body>
<h1>Alphabetical Sorting</h1>
<p>Enter a string to sort alphabetically:</p>
<input type="text" id="inputString" placeholder="Enter a string">
<button onclick="sortAndDisplay()">Sort</button>
<p>Sorted String: <span id="result"></span></p>
<script>
function sortStringAlphabetically(inputString) {
const charArray = inputString.split('');
const sortedArray = charArray.sort();
const sortedString = sortedArray.join('');
return sortedString;
}
function sortAndDisplay() {
const inputElement = document.getElementById("inputString");
const resultElement = document.getElementById("result");
const inputValue = inputElement.value;
const sortedValue = sortStringAlphabetically(inputValue);
resultElement.textContent = sortedValue;
}
</script>
</body>
</html>