scrimba
Letterbox Swapping the buttons
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Letterbox Swapping the buttons
AboutCommentsNotes
Letterbox Swapping the buttons
Expand for more info
index.js
run
preview
console
let wordToGuess = ''
let playerAttempt = ''
const startBtn = document.getElementsByClassName('start-btn')[0]
const resetBtn = document.getElementsByClassName('reset-btn')[0]

// Grab the div to hold the keyboard
const playerKeyboard = document.getElementsByClassName('player-keyboard')[0]
const blanksDisplayBox = document.getElementsByClassName('blanks-display-box')[0]


// Create variables for unicode a and z
const unicodeA = 97
const unicodeZ = 122

// Write a function to create the keyboard and call it
function createKeyboard() {
for (let i = unicodeA; i <= unicodeZ; i++) {
const character = String.fromCharCode(i)
const letterButton = document.createElement('button')
letterButton.className = 'letter-btn'
letterButton.setAttribute('id', character)
letterButton.innerText = character
letterButton.addEventListener('click', handleGuess)
playerKeyboard.appendChild(letterButton)
}
}
createKeyboard()

//http://random-word-api.herokuapp.com/home
function handleStart(){
const url = 'https://random-word-api.herokuapp.com/word?number=1&swear=0'
fetch(url)
.then(response => response.json())
.then(data => {
wordToGuess = data.toString()
console.log(wordToGuess)
for (let i =0; i<wordToGuess.length; i++){
playerAttempt += '-'
}
blanksDisplayBox.innerText = playerAttempt
})
}




function handleGuess(){
}





Console
/index.html
-1:56