Home / Expert Answers / Computer Science / html-documents-can-use-the-nbsp-lt-script-gt-nbsp-tag-to-reference-javascript-in-a-separate-file-o-pa514

(Solved): HTML documents can use the <script> tag to reference JavaScript in a separate file o ...



HTML documents can use the <script> tag to reference JavaScript in a separate file or to incorporate the code inside the same HTML file. Write a program that reads an HTML file and prints the contents of the <script> tag. For example, consider the following lines of a sample HTML file:

<head>
   <title>HTML Resources</title>
   <script>
      function getage(birthdate) {
         var Bday = +new Date(birthdate);
         /* Forgot why I needed "~~"; why didn't I add a comment? :-( */
         age = ~~ ((Date.now() - Bday) / (31557600000));
         return age;
      }
   </script>
   <link href="css/colegiocoop.css" rel="stylesheet">
</head>
<body>
    <header>

Your program should print the following:

   <script>
      function getage(birthdate) {
         var Bday = +new Date(birthdate);
         /* Forgot why I needed "~~"; why didn't I add a comment? :-( */
         age = ~~ ((Date.now() - Bday) / (31557600000));
         return age;
      }
   </script>

Note: You should not assume that the script tag will be in any particular line or before/after any particular tag. Also, there might be whitespace (such as a space or a tab) at the beginning of the line where the script tag opens or closes, but you can assume there will be no other tags on those lines.

 

(PYTHON LANGUAGE)



We have an Answer from Expert

View Expert Answer

Expert Answer


Using regular expression matching, content of the script tags are extracted import
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe