-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
68 lines (40 loc) · 1.89 KB
/
app.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { twoSum } from './scripts/two-sum.js';
import { isPalindrome } from './scripts/palindrome.js';
import { romanToInt } from './scripts/roman-to-integer.js';
import { intToRoman } from './scripts/integer-to-roman.js';
// spoiler
document.querySelectorAll('.spoiler__button').forEach((item) => {
item.addEventListener('click', (event) => {
event.target.closest('.spoiler').classList.toggle('spoiler--active')
})
})
// two sum section
const sumArrayInput = document.querySelector('[data-sum-array]');
const sumTargetInput = document.querySelector('[data-sum-target]');
const sumButton = document.querySelector('[data-sum-btn]');
let sumArray = [];
let sumTarget;
sumButton.addEventListener('click', () => {
let sumArrayStr = sumArrayInput.value.split(',');
sumArray = sumArrayStr.map(item => Number(item));
sumTarget = Number(sumTargetInput.value);
document.querySelector('[data-sum-result]').innerHTML = String(twoSum(sumArray, sumTarget));
})
// palindrome section
const palindromeInput = document.querySelector('[data-palindrome-input]');
const palindromeBtn = document.querySelector('[data-palindrome-btn]');
palindromeBtn.addEventListener('click', () => {
document.querySelector('[data-palindrome-result]').innerHTML = String(isPalindrome(Number(palindromeInput.value)))
});
// integer to roman section
const integerInput = document.querySelector('[data-integer-input]');
const integerBtn = document.querySelector('[data-integer-btn]');
integerBtn.addEventListener('click', () => {
document.querySelector('[data-integer-result]').innerHTML = intToRoman(integerInput.value);
});
// roman to integer section
const romansInput = document.querySelector('[data-romans-input]');
const romansBtn = document.querySelector('[data-romans-btn]');
romansBtn.addEventListener('click', () => {
document.querySelector('[data-romans-result]').innerHTML = romanToInt(romansInput.value);
});