avr39ripe

jsLoopPractice

Feb 1st, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.53 KB | None | 0 0
  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.         const maxColor = 3;
  11.         const cRed = 0;
  12.         const cGreen = 1;
  13.         const cBlue = 2;
  14.         let color = 0; // 0 - Red, 1 - Green, 2 - blue
  15.  
  16.         do {
  17.             if (color == cRed) {
  18.                 alert('Red');
  19.             }
  20.             else if (color == cGreen) {
  21.                 alert('Green');
  22.             }
  23.             else if (color == cBlue) {
  24.                 alert('Blue');
  25.             }
  26.             else {
  27.                 alert('ERROR: Unknown color!');
  28.             }
  29.  
  30.             ++color;
  31.  
  32.             color %= maxColor;
  33.  
  34.             //if (color > maxColor) {
  35.             //    color = cRed;
  36.             //}
  37.  
  38.             //Red - Green - Blue
  39.  
  40.             // Blue [ Red ] Green
  41.             // Red [ Green ] Blue
  42.             // Green [ Blue ] Red
  43.             // Blue [ Red ] Green
  44.  
  45.         } while (confirm('One more color?'));
  46.  
  47.         //let color = 'Blue';
  48.  
  49.         //do {
  50.         //    alert(`Current color is: ${color}`);
  51.  
  52.         //    if (color == 'Red') {
  53.         //        color = 'Green'
  54.         //    }
  55.         //    else if (color == 'Green') {
  56.         //        color = 'Blue'
  57.         //    }
  58.         //    else if (color == 'Blue') {
  59.         //        color = 'Red'
  60.         //    }
  61.  
  62.         //} while (confirm('One more color?'));
  63.  
  64.         console.log('Job is DONE! :)');
  65.        
  66.  
  67.     </script>
  68. </body>
  69. </html>
  70.  
Advertisement
Add Comment
Please, Sign In to add comment