-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (25 loc) · 1.01 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
const button = document.querySelector('button');
const textarea = document.querySelector('.textarea');
const resultText = document.querySelector('.result-text');
function replaceText () {
const regex = /(\w+)/g;
const str = textarea.value;
const results = str.split(regex);
console.log(results);
results.forEach(result => {
const span = document.createElement('span');
span.innerHTML = result;
resultText.appendChild(span);
span.addEventListener('mouseover', () =>{
const randomColor1 = Math.floor(Math.random() * 255);
const randomColor2 = Math.floor(Math.random() * 255);
const randomColor3 = Math.floor(Math.random() * 255);
span.style.backgroundColor = `rgba(${randomColor1}, ${randomColor2}, ${randomColor3})`;
});
})
//resultText.innerHTML = results;
};
button.addEventListener('click', () => {
resultText.innerHTML = `<p class ="text-info"> This is what I matched 🔥 </p>`;
replaceText();
})