I'm developing a pure JavaScript hangman game and facing an issue with splitting words from an array into single letters. When I split the array, I get "," for every letter.
For example, when I split the word [station]
, it returns "s,t,a,t,i,o,n
".
My goal is to split the word without adding the "," between letters.
Below is the code snippet I'm currently using:
// Array of words for the hangman game
let words = ["definition", "programming", "relation", "station", "gamification", "playstation"];
// Randomly select a word from the array
let random = Math.floor(Math.random(words) * words.length);
// Split the selected word into individual letters (e.g., station to [s,t,a,t,i,o,n])
let wordSplit = words[random].split('');
// Display the word split into letters
let wordLetters = document.getElementById("letters")
wordLetters.innerHTML = wordSplit;
function wordInput(){
let lettersDiv = document.getElementById("letters");
let html = "<p id = 'letters'>" + wordSplit + "</p>";
return html;
}