Skip to content

Commit 57b4fc0

Browse files
committed
strings part 2 done
1 parent 85261a9 commit 57b4fc0

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

stringing-characters-together/exercises/part-two.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ let dna = " TCG-TAC-gaC-TAC-CGT-CAG-ACT-TAa-CcA-GTC-cAt-AGA-GCT ";
44

55
// First, print out the dna strand in it's current state.
66

7+
console.log(dna);
8+
79
//1) Use the .trim() method to remove the leading and trailing whitespace, then print the result.
810

9-
console.log(/* Your code here. */);
11+
console.log(dna.trim());
1012

1113
//2) Change all of the letters in the dna string to UPPERCASE, then print the result.
1214

13-
console.log();
15+
console.log(dna.toUpperCase().trim());
1416

1517
//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.
1618
//Apply these fixes to your code so that console.log(dna) prints the DNA strand in UPPERCASE with no whitespace.
1719

20+
dna = dna.toUpperCase().trim();
21+
1822
console.log(dna);
1923

2024
//Part Two Section Two
@@ -23,10 +27,25 @@ let dnaTwo = "TCG-TAC-GAC-TAC-CGT-CAG-ACT-TAA-CCA-GTC-CAT-AGA-GCT";
2327

2428
//1) Replace the gene "GCT" with "AGG", and then print the altered strand.
2529

30+
dnaTwo = dnaTwo.replace("GCT", "AGG");
31+
console.log(dnaTwo);
32+
2633
//2) Look for the gene "CAT" with ``indexOf()``. If found print, "CAT gene found", otherwise print, "CAT gene NOT found".
2734

35+
if (dnaTwo.indexOf("CAT") === -1) {
36+
console.log("CAT gene NOT found.");
37+
} else {
38+
console.log("CAT gene found.")
39+
}
40+
2841
//3) Use .slice() to print out the fifth gene (set of 3 characters) from the DNA strand.
2942

43+
console.log(dnaTwo.slice(16, 19));
44+
3045
//4) Use a template literal to print, "The DNA strand is ___ characters long."
3146

47+
console.log(`The DNA strand is ${dnaTwo.length - 1} characters long.`)
48+
3249
//5) Just for fun, apply methods to ``dna`` and use another template literal to print, 'taco cat'.
50+
51+
console.log(`${dna.slice(4,7).toLowerCase()}o ${dna.slice(dna.indexOf('CAT'),dna.indexOf('CAT')+3).toLowerCase()}`);

0 commit comments

Comments
 (0)