<!DOCTYPE html> <meta charset="utf-8"> <head> <title>Essaie des ID </title> </head> <script type="text/javascript"> function travail() { // function var userInput = document.getElementById('userInput'); var o = document.getElementById("mondiv"); var name = userInput.value var consonneMin = 'cdfghjklmnpqrstvwxyz'; var consonneMaj = consonneMin.toUpperCase(); var consonne = consonneMin + consonneMaj var voyelleMin = 'aeiou'; var voyelleMaj = voyelleMin.toUpperCase(); var voyelle = voyelleMin + voyelleMaj + ':?'; var espace = ' '; for (count=0; count<name.length; count++) { // for name count var daChar = name.charAt(count); var result = ""; for (i = 0; i < consonne.length; i++) { // for consonne i if (daChar == consonne.charAt(i)) { // if consonne result += ''+ daChar + ''; } // end if consonne } // end for consonne for (a = 0; a < voyelle.length; a++) { // for voyelle a if (daChar == voyelle.charAt(a)) { // if voyelle result += ''+ daChar + ''; } // end if voyelle } // end for voyelle for (b = 0; b < espace.length; b++) { // for espace if (daChar == espace.charAt(b)) { // if espace result += ''+ daChar + ''; } // end if espace } // end for espace o.innerHTML += result; } // end for count } // end function </script> </html>
<!DOCTYPE> <meta charset="utf-8"> <head> <title>Essaie des ID</title> </head> <script type="text/javascript"> function travail() { // function var userInput = document.getElementById('userInput'); var o = document.getElementById("mondiv"); var name = userInput.value var consonne= 'cdfghjklmnpqrstvwxyz'; var voyelle= 'aeiou'; var result = ''; for (count=0; count<name.length; count++) { // for name count daChar = name.charCodeAt(count); if(String.fromCharCode(daChar) != " ") { for (i = 0; i < consonne.length; i++) { // for consonne i if (daChar == consonne.charCodeAt(i)) { // if consonne result += ''+ String.fromCharCode(daChar) +''; } // end if consonne } // end for consonne for (a = 0; a < voyelle.length; a++) { // for voyelle a if (daChar == voyelle.charCodeAt(a)) { // if voyelle result += ''+ String.fromCharCode(daChar) + ''; } // end if voyelle } // end for voyelle } else { result += " "; } } // end for count o.innerHTML = result; } // end function </script> test </html>
var result = ""; [...] if (daChar == voyelle.charCodeAt(a)) { result += ''+ daChar + ''; } //a la fin de la fonction: o.innerHTML = result;
<!DOCTYPE html> <meta charset="utf-8"> <head> <title>Essaie des ID </title> </head> <script type="text/javascript"> function travail() { // function var userInput = document.getElementById('userInput'); var o = document.getElementById("mondiv"); var name = userInput.value var consonne= 'cdfghjklmnpqrstvwxyz'; var voyelle= 'aeiou'; for (count=0; count<name.length; count++) { // for name count var daChar = name.charCodeAt(count); var result = ""; for (i = 0; i < consonne.length; i++) { // for consonne i if (daChar == consonne.charCodeAt(i)) { // if consonne result += ''+ daChar + ''; } // end if consonne } // end for consonne for (a = 0; a < voyelle.length; a++) { // for voyelle a if (daChar == voyelle.charCodeAt(a)) { // if voyelle result += ''+ daChar + ''; } // end if voyelle } // end for voyelle } // end for count o.innerHTML = name; } // end function </script> test </html>
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionString.fromCharCode(daChar)Il faut aussi rajouter une condition pour les espaces.
o.innerHTML += ''+ String.fromCharCode(daChar) + '';