Vous êtes sur la page 1sur 3

Correction Tp 4 :

<!-- HTML Exercice 4.1 -->


         <!-- <form name="f1">
         <label for="chaine">Donner une CHAINE</label>
         <input type="text" name="chaine">
         <input type="button" onclick="aff()" value="afficher">
         </form> -->

// Exercice 4.1
            // function aff(){
            //     let ch= document.f1.chaine.value ;
            //     if((ch.length>6) || (ch.length==0)){
            //         alert("Erreur");
            //     }
            //     else{
            //         document.write(ch.fontsize(5) +"<br/>");
            //         document.write(ch.fontcolor("red")+"<br/>");
            //         document.write(ch.italics()+"<br/>");
            //         document.write(ch.length+"<br/>");
            //         document.write(ch.charAt(0)+"<br/>");
            //         document.write(ch.charAt(ch.length-1)+"<br/>");
            //         document.write(ch.substring(0,3)+"<br/>");
            //         //document.write(ch.split(" ").length+"<br/>");
            //         let nbc=0;
            //         for(let i=0;i<=ch.length-1;i++){
            //             if((!isNaN(ch.charAt(i))) && ((ch.charAt(i))!==" ")){
            //                 nbc=nbc+1;
            //             }
            //         }
            //         document.write("Nombres de chiffres est "+ nbc +"<br/>");
            //         let nbrMot=1;
            //         for(let i=0;i<=ch.length-1;i++){
            //             if(ch.charAt(i)===" "){
            //                 nbrMot=nbrMot+1;
            //             }
            //         }
            //         document.write("Le nombre des mots est "+nbrMot+"<br>");
            //         document.write(ch.strike()+"<br/>");
            //         document.write(ch.big().big()+"<br/>");
            //         document.write(ch.small()+"<br/>");
            //         document.write(ch.blink()+"<br/>");
            //         document.write(ch.sub()+"<br/>");
            //         document.write(ch.sup()+"<br/>");
            //         document.write(ch.bold()+"<br/>");
            //     }
            // }
<!-- HTML Exercice 4.2 -->
         <!-- <form name="f1">
            <label for="MAIL"><h3>ADRESSE MAIL:</label>
            <input type="text" name="MAIL" size="30"/>
            <input type="button" onclick="verif()" name="b1" value="VALIDER"/></h3>
         </form> -->
/ Exercice 4.2
            // function verif(){
            //     if((document.f1.MAIL.value.startsWith("@"))||(document.f1.MAIL.value.endsWith("@"))||
(document.f1.MAIL.value.indexOf("@")===-1)||(document.f1.MAIL.value.indexOf(".")===-1)||
(document.f1.MAIL.value.indexOf(".")===document.f1.MAIL.value.length-1)){
            //         alert("MAIL non valide");
            //     }
            //     else{
            //         alert("MAIL valide");
            //     }
            // }
<!-- HTML Exercice 4.3 -->
         <!-- <form name="f1">
            <label for="t1">Donner la chaine de caractères:</label>
            <input type="text" name="t1"/>
            <input type="button" onclick="inv()" value="inverser"/>
            <input type="text" name="t2">
         </form> -->
// Exercice 4.3
        //     function inv(){
        //         let ch=document.f1.t1.value ;
        //         if(document.f1.t1.value.length===0){
        //             alert("Chaine vide")
        //         }
        //         else{
        //         for(let i=ch.length-1;i>=0;i--){
        //             document.f1.t2.value=document.f1.t2.value+ch.charAt(i);
        //         }
        //     }
        //     // L'instruction li te7t hadhi est une deuxième solution bel split w reverse w join
        //     // document.f1.t2.value = document.f1.t1.value.split("").reverse().join("") ;
        //   }
<!-- HTML Exercice 4.4 -->
         <!-- <form name="form3">
            <input type="radio" name="choix" id="choix1" onclick="afficher()" value="ORANGE"/>
            <label for="choix1">ORANGE</label><br/>
            <input type="radio" name="choix" onclick="afficher()" value="POMME" id="choix2"/>
            <label for="choix2">POMME</label><br/>
            <input type="text" name="t1"/>
         </form> -->
// Exercice 4.4
            // function afficher(){
            //     Première solution
            //     document.form3.t1.value=document.form3.choix.value ;
            //     Deuxième solution
            //     if(document.form3.choix[0].checked){
            //         document.form3.t1.value=document.form3.choix[0].value ;
            //     }
            //     if(document.form3.choix[1].checked){
            //         document.form3.t1.value=document.form3.choix[1].value;
            //     }
            //     3eme solution
            //     if(document.getElementById("choix1").checked){
            //         document.form3.t1.value=document.getElementById("choix1").value ;
            //     }
            //     if(document.getElementById("choix2").checked){
            //         document.form3.t1.value=document.getElementById("choix2").value ;
            //     }
            // }
<!-- HTML Exercice 4.5 -->
         <!-- <p>Entrez votre choix:</p>
         <form name="form4">
            <input type="checkbox" name="c1" value="1"/>
            <label for="c1">Choix numéro 1</label><br/>
            <input type="checkbox" name="c2" value="2"/>
            <label for="c2">Choix numéro 2</label></br>
            <input type="checkbox" name="c3" value="3"/>
            <label for="c3">Choix numéro 3</label><br/>
            <input type="button" name="but" onclick="reponse()" value="Corriger"/>
         </form> -->
// Exercice 4.5
            // function reponse(){
            //     if((document.form4.c1.checked)&&(document.form4.c2.checked)&&(!
document.form4.c3.checked)){
            //         alert("Une bonne réponse")
            //     }
            //     else{
            //         alert("Désolé, continuez à cherchez")
            //     }
            // }
<!-- HTML Exercice 4.6 -->
         <!-- Entrez votre choix :
         <form name="f1">
            <select name="liste">
                <option value="1">Elément 1</option>
                <option value="2">Elément 2</option>
                <option value="3">Elément 3</option>
            </select>
            <input type="button" name="b" onclick="choisir()" value="Quel est l'élément retenu?"/>
         </form> -->
// Exercice 4.6
            // function choisir(){
            //     Premiére solution
                // if(document.f1.liste.options[0].selected){
                //     alert("L'élément "+document.f1.liste.options[0].value);
                // }
                // else if(document.f1.liste.options[1].selected){
                //     alert("L'élément "+document.f1.liste.options[1].value);
                // }
                // else{
                //     alert("L'élément "+document.f1.liste.options[2].value);
                // }
            //     Deuxième solution
            //     alert("L'élément "+(document.f1.liste.selectedIndex+1));
            // }
<!-- HTML Exercice 4.7 -->
         <!-- <form name="form5">
            <select onclick="couleur()" name="list">
                <option value="red">rouge</option>
                <option value="green">vert</option>
                <option value="yellow">jaune</option>
            </select>
</form> -->

// Exercice 4.7
        //     function couleur(){
        //     //    
document.bgColor=document.form5.list.options[document.form5.list.selectedIndex].value;

Vous aimerez peut-être aussi