| 12
 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
 
 | var phrase = prompt("entrez une phrase");
var comptMot = 0;    
for(var i = 0; i<=phrase.length; i++){
 
    if(phrase.charAt(0)== " "|| phrase.charAt(0)== ","|| phrase.charAt(0)== "."|| phrase.charAt(0)== ":"|| phrase.charAt(0)== ";"|| phrase.charAt(0)== "?"|| phrase.charAt(0)== "!"|| phrase.charAt(0)=="-"){// si l'utilisateur commence sa phrase par un caractere separateur de mots
    i++;
    }
 
    if(phrase.charAt(i)== " "|| phrase.charAt(i)== ","|| phrase.charAt(i)== "."|| phrase.charAt(i)== ":"|| phrase.charAt(i)== ";"|| phrase.charAt(i)== "?"|| phrase.charAt(i)== "!"|| phrase.charAt(i)== "-"){//si le caractere a la position i est l'un des caracteres separateur de mots
 
 
       if(phrase.charAt(i+1)== " "|| phrase.charAt(i+1)== ","|| phrase.charAt(i+1)== "."|| phrase.charAt(i+1)== ":"|| phrase.charAt(i+1)== ";"|| phrase.charAt(i+1)== "?"|| phrase.charAt(i+1)== "!"|| phrase.charAt(i+1)== "-"){//si en plus le caractere a la position i+1 est l'un des caracteres separateurs
        i++;
           while(phrase.charAt(i+1)== " "|| phrase.charAt(i+1)== ","|| phrase.charAt(i+1)== "."|| phrase.charAt(i+1)== ":"|| phrase.charAt(i+1)== ";"|| phrase.charAt(i+1)== "?"|| phrase.charAt(i+1)== "!"|| phrase.charAt(i+1)== "-" ){//tant que le caractere a la position i+1 est l'un des caracteres separateurs, incrementer
            i++;
           }
       }
 
     comptMot++;
    }
}
 
alert ("il y a "+ comptMot + " mots dans votre  phrase");
 
 
var phraseEnvers = "";
var comptMot = 0;
for(var i =0; i<=phrase.length; i++){
   if(phrase.charAt(0)== " "|| phrase.charAt(0)== ","|| phrase.charAt(0)== "."|| phrase.charAt(0)== ":"|| phrase.charAt(0)== ";"|| phrase.charAt(0)== "?"|| phrase.charAt(0)== "!"|| phrase.charAt(0)=="-"){// si l'utilisateur commence sa phrase par un caractere separateur de mots
    i++;
    }
 
    if(phrase.charAt(i)== " "|| phrase.charAt(i)== ","|| phrase.charAt(i)== "."|| phrase.charAt(i)== ":"|| phrase.charAt(i)== ";"|| phrase.charAt(i)== "?"|| phrase.charAt(i)== "!"|| phrase.charAt(i)== "-"){//si le caractere a la position i est l'un des caracteres separateur de mots
        comptMot++;
        var t = i;
        var j = comptMot-1;
        if(comptMot%2 !=0){//si c'est impair
 
            for(var m = j;m<=t;m++){
                phraseEnvers += phrase.charAt(m); 
            }
            i++;
        }
        if(comptMot%2 ==0){//si c'est pair
            for(var k=t-1;k>=j;k--){
                phraseEnvers += phrase.charAt(m)
            }
            i++
        }
 
 
       if(phrase.charAt(i+1)== " "|| phrase.charAt(i+1)== ","|| phrase.charAt(i+1)== "."|| phrase.charAt(i+1)== ":"|| phrase.charAt(i+1)== ";"|| phrase.charAt(i+1)== "?"|| phrase.charAt(i+1)== "!"|| phrase.charAt(i+1)== "-"){//si en plus le caractere a la position i+1 est l'un des caracteres separateurs
        i++;
           while(phrase.charAt(i+1)== " "|| phrase.charAt(i+1)== ","|| phrase.charAt(i+1)== "."|| phrase.charAt(i+1)== ":"|| phrase.charAt(i+1)== ";"|| phrase.charAt(i+1)== "?"|| phrase.charAt(i+1)== "!"|| phrase.charAt(i+1)== "-" ){//tant que le caractere a la position i+1 est l'un des caracteres separateurs, incrementer
            i++;
           }
       }
 
    } 
}
alert(phraseEnvers); | 
Partager