You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: stringing-characters-together/exercises/part-two.js
+21-2Lines changed: 21 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -4,17 +4,21 @@ let dna = " TCG-TAC-gaC-TAC-CGT-CAG-ACT-TAa-CcA-GTC-cAt-AGA-GCT ";
4
4
5
5
// First, print out the dna strand in it's current state.
6
6
7
+
console.log(dna);
8
+
7
9
//1) Use the .trim() method to remove the leading and trailing whitespace, then print the result.
8
10
9
-
console.log(/* Your code here. */);
11
+
console.log(dna.trim());
10
12
11
13
//2) Change all of the letters in the dna string to UPPERCASE, then print the result.
12
14
13
-
console.log();
15
+
console.log(dna.toUpperCase().trim());
14
16
15
17
//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
18
//Apply these fixes to your code so that console.log(dna) prints the DNA strand in UPPERCASE with no whitespace.
17
19
20
+
dna=dna.toUpperCase().trim();
21
+
18
22
console.log(dna);
19
23
20
24
//Part Two Section Two
@@ -23,10 +27,25 @@ let dnaTwo = "TCG-TAC-GAC-TAC-CGT-CAG-ACT-TAA-CCA-GTC-CAT-AGA-GCT";
23
27
24
28
//1) Replace the gene "GCT" with "AGG", and then print the altered strand.
25
29
30
+
dnaTwo=dnaTwo.replace("GCT","AGG");
31
+
console.log(dnaTwo);
32
+
26
33
//2) Look for the gene "CAT" with ``indexOf()``. If found print, "CAT gene found", otherwise print, "CAT gene NOT found".
27
34
35
+
if(dnaTwo.indexOf("CAT")===-1){
36
+
console.log("CAT gene NOT found.");
37
+
}else{
38
+
console.log("CAT gene found.")
39
+
}
40
+
28
41
//3) Use .slice() to print out the fifth gene (set of 3 characters) from the DNA strand.
29
42
43
+
console.log(dnaTwo.slice(16,19));
44
+
30
45
//4) Use a template literal to print, "The DNA strand is ___ characters long."
31
46
47
+
console.log(`The DNA strand is ${dnaTwo.length-1} characters long.`)
48
+
32
49
//5) Just for fun, apply methods to ``dna`` and use another template literal to print, 'taco cat'.
0 commit comments