Random Word String Generator

by Matthew Vasallo

JavaScript

var word = "hello";

var currentWordIndex = 0;
var totalStringIndex = 0;
var totalStringLength = 10000;
var currentRandomCharLength = 0;
var currentRandomAsciiNum = 0;
var currentRandomLowerCaseLetter = "";
var currentString = "";

//create a string that's of totalStringLength and has the word HELLO scattered in order throughout with random letters in between the letters.
while (++totalStringIndex < totalStringLength) {
  //random length between 1-10 of how many chars to insert between
  currentRandomCharLength = Math.floor((Math.random() * 10) + 1);
  for (var i = 0; i <= currentRandomCharLength; i++) {
    //random lower case letter between a (97 ascii) and z (121 ascii)
    currentRandomAsciiNum = Math.floor(Math.random() * 25);
    currentRandomLowerCaseLetter = String.fromCharCode(97 + currentRandomAsciiNum);
    currentString += currentRandomLowerCaseLetter;
  }
  //Add a letter from the word
  currentString += word.charAt(currentWordIndex);
  currentWordIndex++;

  if (currentWordIndex === word.length) {
    currentWordIndex = 0;
  }
  
}

console.log(currentString);