diff --git a/html/game.js b/html/game.js
index 27139ec..4863081 100644
--- a/html/game.js
+++ b/html/game.js
@@ -2,17 +2,33 @@ var words = ['google', 'speed', 'window', 'horizon'];
var lives = 6;
var gameWord = words[Math.floor(Math.random() * words.length)].toUpperCase();
-var gameAnswered = new Array(gameWord.length + 1).join('-')
+var gameAnswered = new Array(gameWord.length + 1).join('-');
window.onload = function()
{
- console.log(gameWord)
+ console.log(gameWord) // for DEBUG
document.getElementById("WORD").innerHTML = gameAnswered;
document.getElementById("lives").innerHTML = 'Lives ' + lives;
+
+ // init storage
+ var storageNames = ['gamesWon', 'wordsAnswered', 'gamesFail'];
+ storageNames.forEach(function(item)
+ {
+ if(null == localStorage.getItem(item))
+ localStorage.setItem(item, 0);
+ })
}
function wrong()
{
+ if (lives <= 0)
+ {
+ var gamesFail = localStorage.getItem('gamesFail');
+ localStorage.setItem('gamesFail', parseInt(gamesFail) + 1);
+ alert('You dead');
+ return;
+ }
+
lives -= 1;
document.getElementById("lives").innerHTML = 'Lives ' + lives;
}
@@ -22,19 +38,9 @@ function offChar(char)
var charButton = document.getElementById(char);
charButton.disabled = true;
- if (gameAnswered.split('').indexOf('-') == -1)
- {
- alert('You Win');
- return;
- }
-
- if (lives == 0) {
- alert('You dead');
- return;
- }
-
var indices = [];
var idx = gameWord.split('').indexOf(char)
+
if (idx == -1)
{
wrong();
@@ -46,7 +52,6 @@ function offChar(char)
indices.push(idx);
idx = gameWord.split('').indexOf(char, idx + 1);
}
- console.log(indices)
indices.forEach(function(item, indices)
{
@@ -54,5 +59,15 @@ function offChar(char)
wordArray[item] = char;
gameAnswered = wordArray.join('');
document.getElementById("WORD").innerHTML = gameAnswered;
+ var wordsAnswered = localStorage.getItem('wordsAnswered');
+ localStorage.setItem('wordsAnswered', parseInt(wordsAnswered) + 1);
})
+
+ if (gameAnswered.split('').indexOf('-') == -1)
+ {
+ var gamesWon = localStorage.getItem('gamesWon');
+ localStorage.setItem('gamesWon', parseInt(gamesWon) + 1);
+ alert('You Win');
+ return;
+ }
}
diff --git a/html/styles.css b/html/styles.css
index 9d86808..6b60d55 100644
--- a/html/styles.css
+++ b/html/styles.css
@@ -1,3 +1,5 @@
+// http://paletton.com/#uid=13w0u0kllllaFw0g0qFqFg0w0aF
+
* {
margin: 0; padding: 0; outline: 0;
}