Advertisement
avr39ripe

jsClassMarkerBAD

Mar 28th, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Study</title>
  6. </head>
  7. <body>
  8.     <script>
  9.         'use strict'
  10.         class Marker {
  11.             constructor(color, amountInk) {
  12.                 this.color = color
  13.                 this.ink = amountInk
  14.                 this.charSymvol = this.symvolCount(amountInk)
  15.             }
  16.  
  17.             symvolCount(amountInk) {
  18.                 return amountInk / 0.5
  19.             }
  20.  
  21.             printText(text) {
  22.                 let count = 0;
  23.                 for (let i = 0; i < this.charSymvol; ++i) {
  24.                     ++count;
  25.                     if (text[i] == " ") {
  26.                         ++count;
  27.                     }
  28.                 }
  29.                 return document.writeln(`<p style="color: ${this.color}">${text.substr(0, count)}</p>`);
  30.             }
  31.         }
  32.  
  33.  
  34.         class FillMarker extends Marker {
  35.             constructor(color, amountInk) {
  36.                 super(color, amountInk)
  37.             }
  38.  
  39.             fill(amountInk) {
  40.                 if (amountInk > 100) {
  41.                     this.charSymvol = 100
  42.                 } else {
  43.                     this.charSymvol += this.symvolCount(amountInk)
  44.                 }
  45.             }
  46.         }
  47.  
  48.         let marker1 = new Marker('blue', 13);
  49.         //let msg = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.';
  50.         marker1.printText('Lorem Ipsum is s');
  51.         marker1.printText('Lorem');
  52.         marker1.printText('Ipsum is si');
  53.  
  54.  
  55.         let marker2 = new FillMarker('red', 13);
  56.         marker2.printText('Lorem Ipsum is s');
  57.         marker2.printText('Lorem');
  58.         marker2.printText('Ipsum is simply');
  59.         marker2.fill(20);
  60.         marker2.printText('Lorem Ipsum is simply dummy text of the printing and typesetting industry.');
  61.     </script>
  62. </body>
  63. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement