Hi there,
This is a good start, although in your code, this line will throw an error:
gameSettings();
The reason for this is that you have previously assigned the variable gameSettings
to the result of a confirm dialogue.
var gameSettings = confirm("You are about to start a new game. Start the game with the above settings?");
The disadvantage of this approach is that everything is in the global namespace and you have different bits of functionality intertwined throughout your code.
Now might be a good time to think about how to structure and organize your code, especially as it seems you are making a game - something that cannot usually be done in a few lines of Javascript.
One way of doing this, might be to use the module pattern.
You can read more about it here: http://css-tricks.com/how-do-you-structure-javascript-the-module-pattern-edition/
I have taken the liberty of rewriting the code you have so far:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Game</title>
</head>
<body>
<button class="startgame">Start Game</button>
<button class="newgame">New Game</button>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
var s,
Game = {
settings: {
buttons: $('.startgame, .newgame'),
progress: 0,
existingGameMessage: "Your current game will be lost, are you sure you want to start a new game?",
newGameMessage: "You are about to start a new game. Start the game with the above settings?"
},
bindUIActions: function(){
s.buttons.on("click", function(){
Game.initializeNewGame();
});
},
getConfirmation: function(msg){
return confirm(msg);
},
invokeSettings: function(){
//Do stuff here
},
displayExistingGameDialogue: function(){
if (this.getConfirmation(s.existingGameMessage)){
location.reload(true);
}
},
displayNewGameDialogue: function(){
if (this.getConfirmation(s.newGameMessage)){
location.reload(true);
} else {
Game.invokeSettings();
}
},
initializeNewGame: function(){
if(s.progress){
Game.displayExistingGameDialogue();
} else {
Game.displayNewGameDialogue();
}
},
init: function(){
s = this.settings;
this.bindUIActions();
}
}
Game.init();
</script>
</body>
</html>
Admittedly this results in a few more lines of code, but I’m sure you’ll agree, it is more readable and configurable.
HTH