Avez-vous une question? (216) 97 656 803 hajjriadh@gmail.com
JavaScript

Correction TP les chaînes de caractères en JavaScript

Un cours complet pour maîtriser Correction TP les chaînes de caractères en JavaScript.

0 chapitres 0 QCM Accès gratuit
  1. Objectifs

    • ِEtre capable de manipuler les chaînes de caractères en JavaScript
  2. Exercice 01

    1. Énoncé
    2. Solution
      <!doctype html>
      <html>
      <head>
      <title>JavaScript</title>
      <script language="JavaScript">
      var mot =prompt("Saisir un mot");
      var lg=mot.length;
      document.write("<br><b>Le mot saisie est : "+mot+"</b>");
      document.writeln("<br>La première lettre du mot <strong><span  style='color:blue;'>"+mot+"</span></strong> est: "+mot.charAt(0)+" et il se compose de "+lg+" caractères");
      var lastChar = mot.substr(-1);
      document.writeln("<br>La dernière lettre du mot <strong><span  style='color:blue;'>"+mot+"</span></strong> est: "+lastChar);
      </script> 
      </head>
      <body>
      </body>
      </html>
  3. Exercice 02

    1. Énoncé
    2. Solution
      <!doctype html>
      <html>
      <head>
      <title>TP JavaScript Exe02</title>
      <script language="JavaScript">
      var mot =prompt("Saisir un mot");
      var lg=mot.length;
      document.write("<br><b>Le mot saisie est : "+mot+"</b>");
      document.writeln("<br>La première lettre du mot <strong><span  style='color:blue;'>"+mot+"</span></strong> est: "+mot.charAt(0)+" et il se compose de "+lg+" caractères");
      document.writeln("<br>La deuxème lettre du mot <strong><span  style='color:blue;'>"+mot+"</span></strong> est: "+mot.charAt(1));
      document.writeln("<br>La troisième lettre du mot <strong><span  style='color:blue;'>"+mot+"</span></strong> est: "+mot.charAt(2));
      
      
      document.writeln("<br>La dernière lettre du mot <strong><span  style='color:blue;'>"+mot+"</span></strong> est: "+mot.substr(-1));
      </script> 
      </head>
      <body>
      </body>
      </html>
  4. Exercice 03

    1. Énoncé
    2. Solution
      <!DOCTYPE html> 
      <html> 
         <head> 
            <meta charset="UTF-8" />
               <script language="javascript"> 
               function afficherMessage() {
      document.write('<CENTER><FONT COLOR = "BLUE" size="24px"> Bienvenue à ma page</FONT></CENTER>');
      }
            </script> 
         </head> 
         <body onLoad="afficherMessage();"> 
         </body> 
      </html>