Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add the project
  • Loading branch information
tajulafreen committed Dec 25, 2024
commit 353f0bc6ac29d67ebec371835462763e443d873d
29 changes: 29 additions & 0 deletions Source-Code/InteractivePolling/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Polling App</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="app">
<h1>Vote for Your Favorite Programming Language</h1>
<div class="poll-options">
<button class="poll-option" data-vote="Ruby">Ruby</button>
<button class="poll-option" data-vote="Python">Python</button>
<button class="poll-option" data-vote="Java">Java</button>
<button class="poll-option" data-vote="Javascript">Javascript</button>
</div>
<div class="poll-results">
<h2>Results</h2>
<ul id="results-list">
<!-- Poll results will be displayed here -->
</ul>
</div>
</div>

<!-- JavaScript File -->
<script src="script.js"></script>
</body>
</html>
48 changes: 48 additions & 0 deletions Source-Code/InteractivePolling/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
document.addEventListener('DOMContentLoaded', () => {
const pollOptions = document.querySelectorAll('.poll-option');
const resultsList = document.getElementById('results-list');

const votes = JSON.parse(localStorage.getItem('votes')) || {
Ruby: 0,
Python: 0,
Java: 0,
Javascript: 0,
};

// Update the results on the page
function updateResults() {
resultsList.innerHTML = ''; // Clear previous results

const totalVotes = Object.values(votes).reduce(
(total, count) => total + count,
0,
);

// Display the updated results
Object.entries(votes).forEach(([option, count]) => {
const percentage = totalVotes
? ((count / totalVotes) * 100).toFixed(1)
: 0;

const resultItem = document.createElement('li');
resultItem.innerHTML = `
<strong>${option}</strong>: ${count} votes (${percentage}%)
<div class="bar" style="width: ${percentage}%;"></div>
`;
resultsList.appendChild(resultItem);
});
}

// Display initial poll results
updateResults();

// Event listener for voting
pollOptions.forEach((option) => {
option.addEventListener('click', () => {
const selectedVote = option.getAttribute('data-vote');
votes[selectedVote] += 1;
localStorage.setItem('votes', JSON.stringify(votes));
updateResults();
});
});
});
67 changes: 67 additions & 0 deletions Source-Code/InteractivePolling/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #f9f9f9;
}

.poll-container {
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 400px;
text-align: center;
}

.poll-question {
font-size: 1.2rem;
margin-bottom: 20px;
}

label {
display: block;
margin: 10px 0;
font-size: 1rem;
}

button {
margin-top: 20px;
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}

button:hover {
background-color: #0056b3;
}

.poll-results {
margin-top: 20px;
text-align: left;
}

.poll-results ul {
list-style: none;
padding: 0;
}

.poll-results li {
padding: 5px 0;
font-size: 1rem;
}

.poll-results .bar {
background-color: #007bff;
height: 10px;
border-radius: 4px;
margin-top: 5px;
}