I have the following code here in which you can play the Wheel of Fortune as a one-person game (more than my test for javascript objects).
My problem is that when the screen is small enough, the lines do not seem to break correctly.
For example:

Where is the circle, I have an "empty" square. The reason why I have an empty square is because when the screen is large enough, the square serves as a space between words.
Is there a way in my code to effectively know if an empty square is at the end of the line and not show it, and then the window changes to show it accordingly?
The only thing I had was to add a window.onresize event, which will measure how big the words are related to how big the playground is and decide based on this fact, but it seems very inefficient.
This is my code to create a playing field (starts @ line 266 in my violin ):
WheelGame.prototype.startRound = function (round) { this.round = round; this.lettersInPuzzle = []; this.guessedArray = []; this.puzzleSolved = false; this.currentPuzzle = this.puzzles[this.round].toUpperCase(); this.currentPuzzleArray = this.currentPuzzle.split(""); var currentPuzzleArray = this.currentPuzzleArray; var lettersInPuzzle = this.lettersInPuzzle; var word = document.createElement('div'); displayArea.appendChild(word); word.className = "word"; for (var i = 0; i < currentPuzzleArray.length; ++i) { var span = document.createElement('div'); span.className = "wordLetter "; if (currentPuzzleArray[i] != " ") { span.className += "letter"; if (!(currentPuzzleArray[i] in lettersInPuzzle.toObject())) { lettersInPuzzle.push(currentPuzzleArray[i]); } word.appendChild(span); } else { span.className += "space"; word = document.createElement('div'); displayArea.appendChild(word); word.className = "word"; word.appendChild(span); word = document.createElement('div'); displayArea.appendChild(word); word.className = "word"; } span.id = "letter" + i; } var clear = document.createElement('div'); displayArea.appendChild(clear); clear.className = "clear"; };
javascript html css
Neal
source share