I need to do this exercise to create algorithm in JavaScript:
"Create an algorithm to format names by leaving the first capital letters, example Rodrigo Baptista Oliveira Rodrigo Baptista"
Could someone please help me?
I can not link the function that formats words with alert
.
<button onclick="myFunction()">Clique aqui pequeno Padawan para inserir o nome.</button>
<p id="demo"></p>
<script>
function myFunction() {
var x;
var idade = prompt("Digite o nome desejado Dudu");
}
String.prototype.capitalize = function(allWords) {
return (allWords) ? // if all words
this.split(' ').map(word => word.capitalize()).join(' ') :
this.charAt(0).toUpperCase() + this.slice(1);
}
</script>