Advertisement
PowerCell46

DNA print JS

Nov 25th, 2022
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function printDNA(lengthOfTheDNA) {
  2.  
  3.     let array = ["A", "T", "C", "G", "T", "T", "A", "G", "G", "G"];
  4.     let index = -1;
  5.  
  6.     while (lengthOfTheDNA > 0) {
  7.     let firstRow = `**${array[++index]}${array[++index]}**`;
  8.     console.log(firstRow);
  9.     lengthOfTheDNA--;
  10.  
  11.     if (lengthOfTheDNA === 0) {
  12.       break;
  13.     }
  14.  
  15.     if (index + 1 === Number(array.length)) {
  16.       index = -1;
  17.     }
  18.  
  19.     let secondRow = `*${array[++index]}--${array[++index]}*`;
  20.     console.log(secondRow);
  21.     lengthOfTheDNA--;
  22.  
  23.     if (lengthOfTheDNA === 0) {
  24.       break;
  25.     }
  26.  
  27.     if (index + 1 === Number(array.length)) {
  28.       index = -1;
  29.     }
  30.  
  31.     let thirdRow = `${array[++index]}----${array[++index]}`;
  32.     console.log(thirdRow);
  33.     lengthOfTheDNA--;
  34.  
  35.     if (lengthOfTheDNA === 0) {
  36.       break;
  37.     }
  38.  
  39.     if (index + 1 === Number(array.length)) {
  40.       index = -1;
  41.     }
  42.  
  43.     let forthRow = `*${array[++index]}--${array[++index]}*`;
  44.     console.log(forthRow);
  45.     lengthOfTheDNA--;
  46.  
  47.     if (lengthOfTheDNA === 0) {
  48.       break;
  49.     }
  50.  
  51.     if (index + 1 === Number(array.length)) {
  52.       index = -1;
  53.     }
  54.   }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement