-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (39 loc) · 1.16 KB
/
Copy pathindex.js
File metadata and controls
48 lines (39 loc) · 1.16 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
48
function reverse(form) {
var str = form.rev.value;
var copyButton = document.getElementById("copy-button");
var resultText = document.getElementById("reversed-text");
if (str === "") {
alert("Please enter a value first")
copyButton.disabled = true;
return;
}
if (isPalindrome(str)) {
console.log("Palindrome reads the same backwards as forwards");
resultText.innerHTML = "This word is the same when reversed.";
copyButton.disabled = true;
return;
}
var text = "";
for (i = 0; i <= str.length; i++) {
text = str.substring(i, i + 1) + text;
}
resultText.innerHTML = text;
copyButton.disabled = false;
}
function stopRefresh(event) {
event.preventDefault();
var reverseButton = document.getElementById("reverse-button");
reverseButton.click();
}
function copyReversedText() {
var copiedText = document.getElementById("reversed-text").innerHTML;
navigator.clipboard.writeText(copiedText);
}
function isPalindrome(str) {
for (i = 0; i < str.length / 2; i++) {
if (str.charAt(i) != str.charAt(str.length - 1 - i)) {
return false;
}
}
return true;
}