-3

I'd like to display a number of blank letter spaces = to the number of letters of a random word I pull from an array.

This is for a hangman game for a class project. I have the randomly pulled word and the number of letters in that word but trying to use the variable that I've assigned that number too is proving a bit tricky.

Any help appreciated!

Jarrod
  • 52
  • 1
  • 10
  • 2
    What code do you have so far? – mayersdesign May 06 '17 at 05:28
  • 2
    Can you please post any code that you have tried? – Sreekanth May 06 '17 at 05:28
  • 2
    Welcome to [so]! At this site you are expected to try to **write the code yourself**. After **[doing more research](//meta.stackoverflow.com/questions/261592)** if you have a problem you can **post what you've tried** with a **clear explanation of what isn't working** and providing a [**Minimal, Complete, and Verifiable example**](//stackoverflow.com/help/mcve). I suggest reading [ask] a good question and [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/). Also, be sure to take the [tour] and read **[this](//meta.stackoverflow.com/questions/347937/)**. – Alon Eitan May 06 '17 at 05:28
  • 2
    Wow that was quick. Will update with relevant code asap. – Jarrod May 06 '17 at 05:34

1 Answers1

0

You can try the following code:

// The array of words you have
var $words = [
    'Totidem',
    'Pugnabant',
    'Calidis',
    'Circumfluus',
    'Formaeque'
];
// Pick a random array index
var $idx = Math.floor( Math.random() * $words.length );
// Get the word in the index equal to $idx
var $word = $words[$idx];
// Generate the repeated string. In case you like to display a different
// character, replace the `.join(" ")` with the character you need. For 
// example `.join("_")` or `.join("_=_")`
var $repeated_string = Array( 1 + $word.length).join(" ")
KodeFor.Me
  • 13,069
  • 27
  • 98
  • 166