//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.
// 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