issue with function
Closed this issue · 11 comments
I tried to create a function that would save a "word" and create blank spaces for the length of the word. This is as far as I got.
var word = function () {
for (i=0; i<word.length; i++) {
document.querySelector('input').innerHTML = "text"
}
}
function myGuess () {
for (i = 0; i < alphabet.length; i++) {
var guesses = alphabet[i];
if (alphabet[i] === true) {
console.log[i] }
else { canvasArray(); }
}
}
My repo link is https://github.com/griffind2009/Hangman_Project1
Hey @griffind2009 I think there's some code here that might not be relevant to the problem at hand, what about a function that takes a word
as an argument and returns a string with a blank space for each letter in that word.
What I would recommend is focus on breaking down your game into steps. Before we worry about the DOM, maybe focus on just taking a word, and converting it to underscores.
I did some research on that but couldn't find the solution I was looking for. I saw but I don't think that would work in this case. Do you know of some other possible solutions?
what about something like this:
function convertLettersToUnderscores(word){
var underscores = ''
for(var i = 0; i < word.length; i++){
underscores += "_"
}
return underscores
}
console.log(convertLettersToUnderscores("awesome!"))
That works, thanks! But I think I am missing a variable to create the underscores in the browser. I'm not sure if my question makes sense.
What makes you think that?
I typed in a word and the spaces did not show in the browser, but with console.log they do show in the console.
ok excelletn - so you want to update html - can you select the HTML element and use the .html()
method?
would this be the correct format var getWord = $(".word").html(); ?
yes!
$(".word").html("this will be the new html for the thing with the word class :) ");
It's been awhile so I'm going to close, feel free to reopen or a create a new issue if the problem persists...