-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathindex.js
49 lines (44 loc) · 1.73 KB
/
index.js
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
49
const mirrorString = () => {
const input = document.querySelector("#mirror-input");
const p = document.getElementById("mirror-output");
p.innerText = input.value;
};
const upperCaseString = () => {
const input = document.querySelector("#uppercaser-input");
const p = document.getElementById("uppercaser-output");
p.innerText = input.value.toUpperCase();
};
const checkPalindrome = () => {
const input = document.querySelector("#palindrome-input");
const p = document.getElementById("palindrome-output");
const str = input.value;
let revStr = str.split("").reverse("").join("");
if (str === revStr) {
p.innerText = `It is true that ${input.value} is a palindrome`;
} else {
p.innerText = `It is false that ${input.value} is a palindrome`;
}
};
const isEven = () => {
const input = document.querySelector("#even-checker-input");
const p = document.getElementById("even-checker-output");
const num = input.value;
if (num % 2 === 0) {
p.innerText = `It is true that ${input.value} is even`;
} else {
p.innerText = `It is false that ${input.value} is even`;
}
};
const doubleNumber = () => {
const input = Number(document.querySelector("#doubler-input").value);
const p = document.getElementById("doubler-output");
p.innerText = `${input} doubled is ${input * 2}`;
};
const avgOfNumbers = () => {
const input1 = Number(document.querySelector("#average-input-1").value);
const input2 = Number(document.querySelector("#average-input-2").value);
const input3 = Number(document.querySelector("#average-input-3").value);
const p = document.getElementById("average-output");
const avg = (input1 + input2 + input3) / 3;
p.innerText = `The average of ${input1}, ${input2}, and ${input3} is ${avg}`;
};