1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| <!DOCTYPE html>
<html lang="fr"> <!-- EtudeDicter-.html -->
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>Ici mon titre</title>
</head>
<body>
Le modéle de dictée, <span style="color:red">ATTENTION</span>, il ne doit contenir aucune faute.
<br />
<textarea id="TxtSource" style="position:relative;height:50px;width:450px">Ici le texte de la dictée à reproduire.
L'élève devra faire attention aux fautes d'orthographe.</textarea>
<br /><br />
L'ardoise ou faire la dictée
<br />
<textarea id="TxtArdoise" style="position:relative;height:70px;width:450px">A que pas coucou</textarea>
<br /><br />
<button id="BtnCorrection" onclick="VerifOrtho()">Analyzer</button>
<div id="Result" style="position:relative;width:450px;border-style:double;padding:5px;">L'analyse sera affichée ICI</div>
<script>
//---------------------------------------------------------------------------------------
function VerifOrtho() {
//--------------------------------- création de 2 tableaux, dictée et rédaction --------------------------
document.getElementById("Result").innerHTML = "En cours d'analyse ..... . .";
// partie dictée soumise
let Txt = document.getElementById("TxtSource").value;
let TxtSrc = Txt.trim();
if (TxtSrc.length === 0){ alert("Aucune dicté proposée");return;}
let TblMotSrc = Prepare(TxtSrc).split(" ");
// partie rédaction de l'utilisateur
Txt = document.getElementById("TxtArdoise").value;
let TxtArd = Txt.trim();
if (TxtArd.length === 0){ alert("Aucune rédaction de la dictée");return;}
let TblMotArd = Prepare(TxtArd).split(" ");
let NbrIdxSrc = TblMotSrc.length;
let NbrIdxArd = TblMotArd.length;
// **************** Partie analyse ****************
let Trouver=false, Result="", NbrF=0;
for (let i = 0, iMax = NbrIdxSrc; i < iMax; i++) {
Trouver=false;
for (let t = 0, tMax = NbrIdxArd; t < tMax; t++) {
if (TblMotArd[t]===TblMotSrc[i]){
Result = Result + " " + TblMotArd[t];
Trouver=true;
break;
}
}
if (Trouver===false){
NbrF++;
if(TblMotArd[i]==undefined){
}else{
Result = Result + "<span style='color:red'> " + TblMotArd[i] + "</span>";
}
}
}
console.log("NbrF = ",NbrF);
let comentaire = "<span style='color:green'>Bravo, 0 faute</span><br /><br />";
if (NbrF>=1){
let faute=" faute";
if (NbrF>1){faute=" fautes"}
comentaire = "<span style='color:red'>Pas bien, " + NbrF + faute +"</span><br /><br />";
}
document.getElementById("Result").innerHTML = comentaire + Result;
}//---------------------------------------------------------------------------------------
function Prepare(LeTexte){
let Txt0 = LeTexte.replace(/\n/g," ");//remplace tout retour à la ligne par un espace
let Txt = Txt0.replace(/[\t|.|,|;]/g,"");//remplace toutes tabulations point virgule ou point-virgule par rien
Txt0 = Txt.replace(/( ){2,}/g," ");//remplace les espaces de plus de 2 caractères par un seul espace
return Txt0.trim();
}
</script>
<!-- --------------------------------------------------------------------------------------- -->
</body>
</html> |
Partager