-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (31 loc) · 1.21 KB
/
script.js
File metadata and controls
35 lines (31 loc) · 1.21 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
let entryCount = 0;
const maxEntries = 6;
document.getElementById('nameInput').addEventListener('keypress', function(event) {
if (event.key === 'Enter') {
generatePrice();
}
});
function generatePrice() {
const name = document.getElementById('nameInput').value;
if (name) {
const price = Math.floor(Math.random() * (1000 - 100 + 1)) + 100;
const resultList = document.getElementById('resultList');
const newEntry = document.createElement('div');
newEntry.classList.add('result-entry');
newEntry.innerText = `${name}: $${price}`;
resultList.prepend(newEntry);
entryCount++;
if (entryCount > maxEntries) {
const entries = resultList.querySelectorAll('.result-entry');
const lastEntry = entries[entries.length - 1];
lastEntry.classList.add('hidden');
setTimeout(() => {
resultList.removeChild(lastEntry);
entryCount--;
}, 500); // Allow some time for the visual effect
}
document.getElementById('nameInput').value = ''; // Clear the input field
} else {
alert('Please enter a name.');
}
}