Quotes help make search much faster. Example: "Practice Makes Perfect"

Thursday, November 15, 2012

Codecademy: "Blanks for your Answer"


//sample solution to Hangman Exercise 2


// Fill in this function!
function blanksFromAnswer ( answerWord ) {
   
    //initially, result is a blank string
    var result = ""; // This is the variable we want to use
   
    // Write a loop here to concatanate a '_' to result for
    // every letter in answerWord.
    for(var i=0; i<answerWord.length; i++){
    result = result + "_";
    }
   
    return result;
}
//for testing purposes
console.log(blanksFromAnswer("try"));
//Note: it would have been better if there were spaces between each
//underscore "_", especially if we have long words, but this will
//double the length of the string returned, conflicting with the
//checking mechanics for the exercise.

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts