Learn by Building Workshop Skills GitHub Türkçe Workshop › Connect Four › Step 36 of 38
Counting wins What we are doing The fun is in the series: you against the computer, game after game. Both sides' wins are kept in one object and saved in
localStorage after every win, as JSON text, so they survive a page reload.
```js
let wins = JSON.parse(localStorage.getItem('connect4-wins') || '{"1":0,"2":0}')
wins[who] += 1
localStorage.setItem('connect4-wins', JSON.stringify(wins))
```What it means
getItem reads the saved text, or null the first time; || '{"1":0,"2":0}' falls back to a zero score.
JSON.parse turns the text into an object, JSON.stringify an object into text.
On a win, the winner's count goes up by one and the whole object is saved.
Your turn
Under let thinking write the wins line.
In land, under line = four, write the two lines.
Skills: Game states
← You and the computer Show the score →
All steps A dark background A drawing function The blue board One hole A whole row All 42 holes The board in memory Discs in their colors Draw every frame Where does the disc land? Play a column Taking turns Click to play The next disc Whose turn? Playing with the keyboard Keys 1 to 7 A disc on its way Gravity Watch it fall Inside the board? Walking along a line Four in a row? We have a winner Circle the four Who won? A draw Play again Try a move and take it back Win, or block Don't help the player Prefer the middle The computer's turn Only on your turn You and the computer Counting wins Show the score Build it yourself: the loser starts