Skip to content

Commit 18c9069

Browse files
Refactor JavaScript
1 parent c2fc463 commit 18c9069

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

assets/js/socket.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ let driving = false;
1010
// set up your syncDiff function using updateUsers as a callback
1111

1212
const startButton = document.querySelector('.start-button')
13-
startButton.addEventListener('click', e => {
13+
startButton.addEventListener('click', event => {
1414
driving = true;
1515
// send 'start_pointing' message to the channel here
1616
})
1717

18-
const nextCardButtons = document.getElementsByClassName('next-card')
19-
for (let i = 0;i < nextCardButtons.length; i++) {
20-
nextCardButtons[i].addEventListener('click', e => {
18+
document
19+
.querySelectorAll('.next-card')
20+
.forEach(elem => {
21+
elem.addEventListener('click', event => {
2122
// send 'finalized_points' message to the channel here
23+
})
2224
})
23-
}
2425

2526
document
2627
.querySelector('.calculate-points')
@@ -34,7 +35,7 @@ document
3435
// 'winner'
3536
// 'tie'
3637

37-
function showCard(state) {
38+
const showCard = state => {
3839
document
3940
.querySelector('.start-button')
4041
.style.display = "none"
@@ -58,7 +59,7 @@ function showCard(state) {
5859
.innerHTML = state.card.description
5960
}
6061

61-
function showWinner(state) {
62+
const showWinner = state => {
6263
document
6364
.querySelector('.winner')
6465
.style.display = "block"
@@ -76,7 +77,7 @@ function showWinner(state) {
7677
.disabled = !driving
7778
}
7879

79-
function showTie(state) {
80+
const showTie = state => {
8081
document
8182
.querySelector('.tie')
8283
.style.display = "block"

assets/js/users.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ const usersElem = document.querySelector('.users')
55
const updateUsers = presence => {
66
usersElem.innerHTML = ''
77

8-
// let user = list presences with the help of a listBy function
9-
for(let i = 0; i < users.length; i++) {
10-
addUser(users[i])
11-
}
8+
// let users = list presences with the help of a listBy function
9+
users.forEach(user => addUser(user))
1210

1311
// implement a feature that
1412
// 1. checks if all fo the users in the present list have voted, i.e. have points values that are not nil
1513
// 2. displays the user's vote next to their name if so
1614
}
1715

18-
const listBy = (username, { metas: [{ points }, ..._rest]}) => {
16+
const listBy = (username, {metas: [{points}, ..._rest]}) => {
1917
// build out the listBy function so that it returns a list of users
2018
// where each user looks like this:
2119
// {username: username, points: points}
@@ -26,7 +24,7 @@ const showPoints = usersElem => ({userId, points}) => {
2624
userElem.innerHTML = points
2725
}
2826

29-
function addUser(user) {
27+
const addUser = user => {
3028
const userElem = document.createElement('dt')
3129
userElem.appendChild(document.createTextNode(user.username))
3230
userElem.setAttribute('class', 'col-8')

0 commit comments

Comments
 (0)