Advertisement
Garey

Задачки

Dec 14th, 2017
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <meta charset="utf-8">
  5.     <title>Test</title>
  6.   </head>
  7.   <body>
  8.     <script type="text/javascript">
  9.       function zad_1() {
  10.  
  11.         Array.prototype.longest_string = function() {
  12.           return this.sort(
  13.             function(a, b) {
  14.               if(a.length > b.length) return -1;
  15.               if(a.length < b.length) return 1;
  16.                 return 0;
  17.             }
  18.           )[0];
  19.         }
  20.         let string = prompt("Enter sentence: ")
  21.         string = string.split(" ");
  22.         document.write("<font color=\"blue\">" + string.longest_string() + "</font>")
  23.  
  24.       }
  25.  
  26.  
  27.       function zad_2() {
  28.           let currTime = new Date(Date.now())
  29.  
  30.           if(currTime.getHours() % 2)
  31.             document.write("<font size=\"36px\" color=\"blue\"><b>" + currTime.getHours() + "</b></font>")
  32.       }
  33.  
  34.       function zad_3() {
  35.         document.write("<table border=\"1\"><tr>")
  36.  
  37.         for(i = 1; i < 21; i++) {
  38.           document.write("<td>" + Math.pow(i, 3) + "</td>")
  39.         }
  40.  
  41.         document.write("</tr></table>")
  42.       }
  43.  
  44.       function explode_word(element) {
  45.         if(event.key === 'Enter') {
  46.           document.write("<ol>")
  47.           let string = element.value;
  48.  
  49.           string.split('').forEach( function(character) {
  50.               document.write("<li>" + character + "</li>")
  51.           });
  52.  
  53.           document.write("</ol>")
  54.         }
  55.       }
  56.  
  57.       function zad_4() {
  58.         document.write("<input type=\"text\" onkeydown=\"explode_word(this)\"")
  59.       }
  60.  
  61.       zad_1();
  62.       zad_2();
  63.       zad_3();
  64.       zad_4();
  65.     </script>
  66.   </body>
  67. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement