You are on page 1of 1

// Store all the Letter Buttons

let listOfButtons = [];


// Guess limit of 7
let guess = 0;

// Constructor for the button


function AlphabetButton(letter){
this.letter = letter;
//-----------------Styling---------------------------
this.btn = document.createElement("button");
this.btn.style.width = 50 + "px";
this.btn.style.height = 50 + "px";
this.btn.innerHTML = letter;
this.btn.style.backgroundColor = "grey";
this.btn.style.borderRadius = 12 + "px";
this.btn.style.fontSize = 24 + "px";
this.btn.style.borderWidth = 1 + "px";
this.btn.style.borderStyle = "solid";
this.btn.style.borderColor = "black";
//-----------------Styling---------------------------
document.body.append(this.btn);

// function for when the button is clicked


this.btn.onclick = function() {
console.log("Letter " + letter + " was clicked");// For testing, remove
later
};
}

// Generate all the buttons for all the letters in the Alphabet
function generateButton(){
// a(ACII #97) - z(ACII #122)
for( let i = 97; i <= 122; i++){
// Turn ACII # into a character
let letter = String.fromCharCode(i);
// create an new AlphabetButton object and push it into the array
let newButton = new AlphabetButton(letter);
listOfButtons.push(newButton);

}
}

// Checks button pressed, if the corresponding letter exists in the hidden word
function checkForLetter(){
}
// If user makes a wrong guess, increment guess variable
function guessWrong(){
guess++
// Checks guess variable, user can only have 7 guesses
if(guess > 7) {
alert("GAME OVER!");
}
}

generateButton();

You might also like