ga-wdi-exercises / project1

[project] GA- Project 1
3 stars 75 forks source link

issue with function #266

Closed griffind2009 closed 8 years ago

griffind2009 commented 8 years ago

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

nolds9 commented 8 years ago

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.

nolds9 commented 8 years ago

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.

griffind2009 commented 8 years ago

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?

jshawl commented 8 years ago

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!"))
griffind2009 commented 8 years ago

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.

jshawl commented 8 years ago

What makes you think that?

griffind2009 commented 8 years ago

I typed in a word and the spaces did not show in the browser, but with console.log they do show in the console.

jshawl commented 8 years ago

ok excelletn - so you want to update html - can you select the HTML element and use the .html() method?

griffind2009 commented 8 years ago

would this be the correct format var getWord = $(".word").html(); ?

jshawl commented 8 years ago

yes!

$(".word").html("this will be the new html for the thing with the word class :) ");
nolds9 commented 8 years ago

It's been awhile so I'm going to close, feel free to reopen or a create a new issue if the problem persists...