|
1 | 1 | //Part Two Section One
|
2 | 2 |
|
3 |
| -let dna = " TCG-TAC-gaC-TAC-CGT-CAG-ACT-TAa-CcA-GTC-cAt-AGA-GCT "; |
| 3 | +let dna = " TCG-TAC-gaC-TAC-CGT-CAG-ACT-TAa-CcA-GTC-cAt-AGA-GCT ".trim().toUpperCase(); |
4 | 4 |
|
5 | 5 | // First, print out the dna strand in it's current state.
|
6 |
| - |
| 6 | +console.log(dna); |
7 | 7 | //1) Use the .trim() method to remove the leading and trailing whitespace, then print the result.
|
8 |
| - |
9 |
| -console.log(/* Your code here. */); |
10 |
| - |
| 8 | +let newDna = dna.trim(); |
| 9 | +console.log(newDna); |
11 | 10 | //2) Change all of the letters in the dna string to UPPERCASE, then print the result.
|
12 |
| - |
13 |
| -console.log(); |
| 11 | +let dnaUpper = dna.toUpperCase(); |
| 12 | +console.log(dnaUpper); |
14 | 13 |
|
15 | 14 | //3) Note that after applying the methods above, the original, flawed string is still stored in dna. To fix this, we need to reassign the changes to back to dna.
|
16 | 15 | //Apply these fixes to your code so that console.log(dna) prints the DNA strand in UPPERCASE with no whitespace.
|
17 | 16 |
|
18 |
| -console.log(dna); |
| 17 | +//console.log(dna); |
19 | 18 |
|
20 | 19 | //Part Two Section Two
|
21 | 20 |
|
22 | 21 | let dnaTwo = "TCG-TAC-GAC-TAC-CGT-CAG-ACT-TAA-CCA-GTC-CAT-AGA-GCT";
|
23 |
| - |
| 22 | +console.log(dnaTwo.indexOf('CAT')); |
24 | 23 | //1) Replace the gene "GCT" with "AGG", and then print the altered strand.
|
25 |
| - |
| 24 | +let dnaTwoReplace = dnaTwo.replace('GCT', 'AGG'); |
| 25 | +console.log(dnaTwoReplace); |
26 | 26 | //2) Look for the gene "CAT" with ``indexOf()``. If found print, "CAT gene found", otherwise print, "CAT gene NOT found".
|
27 |
| - |
| 27 | +if (dnaTwo.indexOf("CAT") === 40){ |
| 28 | + console.log("CAT gene found"); |
| 29 | +}else{ |
| 30 | + console.log("CAT gene NOT found"); |
| 31 | +} |
28 | 32 | //3) Use .slice() to print out the fifth gene (set of 3 characters) from the DNA strand.
|
29 |
| - |
| 33 | +console.log(dnaTwo.slice(16, 19)); |
30 | 34 | //4) Use a template literal to print, "The DNA strand is ___ characters long."
|
31 |
| - |
| 35 | +console.log(`The DNA strand is ${dnaTwo.length} characters long`); |
32 | 36 | //5) Just for fun, apply methods to ``dna`` and use another template literal to print, 'taco cat'.
|
| 37 | +console.log(`${dna.slice(4,7).toLowerCase()}o ${dna.slice(dna.indexOf('CAT'),dna.indexOf('CAT')+3).toLowerCase()}`); |
0 commit comments