How can I replace all characters in a given string with *
using the replaceAll()
function?
var words = ['marvel','computer','regex','throne'];
var rand = words[Math.floor(Math.random() * words.length)];
//should replace all characters in the string with *
$('#value').text(rand).replaceAll(rand,'*');
.container{
border: 1px solid black;
padding: 5px;
margin: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='container'>
<input type='text' />
<span id='value'></span>
<hr />
<button type='button' id='submit'>Submit</button>
</div>
Id rather not go down the regex route but Im guessing I may have to.
Im writing a simple hangman program for fun that hides the string with *
characters. The user then enters a character and if correct the character in the string is reset back to its original.
regex is great for stuff like this, im just not that familiar with it.