-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
25 lines (21 loc) · 858 Bytes
/
app.js
File metadata and controls
25 lines (21 loc) · 858 Bytes
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
const textInput = document.querySelector("#text-input");
const textOutput = document.querySelector("#text-output");
const revBtn = document.querySelector(".rev-btn");
const copyBtn = document.querySelector("#copy-btn");
textOutput.spellcheck = false;
textInput.spellcheck = false;
// Add Events to the form & copy button
revBtn.addEventListener("click", reverseString);
copyBtn.addEventListener("click", copyText);
function reverseString(event) {
event.preventDefault();
const text = textInput.value.split(""); // Convert string to an array e.g: ["h", "e", "l", "l", "o"]
const revText = text.reduceRight((acc, curr) => acc + curr, "");
textOutput.value = revText; // set the output to textOutput
}
function copyText(event) {
event.preventDefault();
if (textOutput.value <= 0) return;
textOutput.select();
document.execCommand("copy");
}