Skip to content

Commit 35bb7b8

Browse files
committed
StringingCharactersTogether: ExercisesP.2
1 parent fd40b97 commit 35bb7b8

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,52 @@
33
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.
6-
6+
console.log(dna)
77
//1) Use the .trim() method to remove the leading and trailing whitespace, then print the result.
8-
9-
console.log(/* Your code here. */);
8+
let dna2 = dna.trim()
9+
console.log(dna2/* Your code here. */);
1010

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

13-
console.log();
13+
console.log(dna.toUpperCase());
1414

1515
//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.
1616
//Apply these fixes to your code so that console.log(dna) prints the DNA strand in UPPERCASE with no whitespace.
17-
18-
console.log(dna);
17+
dna = "TCG-TAC-gaC-TAC-CGT-CAG-ACT-TAa-CcA-GTC-cAt-AGA-GCT"
18+
console.log(dna.toUpperCase());
1919

2020
//Part Two Section Two
2121

2222
let dnaTwo = "TCG-TAC-GAC-TAC-CGT-CAG-ACT-TAA-CCA-GTC-CAT-AGA-GCT";
2323

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

26-
//2) Look for the gene "CAT" with ``indexOf()``. If found print, "CAT gene found", otherwise print, "CAT gene NOT found".
26+
console.log(dnaTwo.replace("GCT","AGG"))
2727

28+
//2) Look for the gene "CAT" with ``indexOf()``. If found print, "CAT gene found", otherwise print, "CAT gene NOT found".
29+
let indexOf = "CAT";
30+
if (String(dnaTwo).includes("CAT")){
31+
console.log("CAT gene found.");
32+
} else {console.log("CAT gene not found");
33+
}
2834
//3) Use .slice() to print out the fifth gene (set of 3 characters) from the DNA strand.
2935

30-
//4) Use a template literal to print, "The DNA strand is ___ characters long."
36+
console.log(String(dnaTwo.indexOf('CGT')));
37+
console.log(String(dnaTwo.indexOf('-CAG')))
38+
console.log(String(dnaTwo.slice(16,19)))
39+
//used the index to find the beginning and ending of the desired strand, within the string; and sliced it with corresponding numbers//
3140

41+
//4) Use a template literal to print, "The DNA strand is ___ characters long."
42+
console.log(dnaTwo.length)
43+
let dnaLength = 51;
44+
let variable1 = "DNA strand"
45+
let tc = 'taco cat'
46+
console.log(`"The ${variable1} is ${dnaLength} characters long."`);
3247
//5) Just for fun, apply methods to ``dna`` and use another template literal to print, 'taco cat'.
48+
49+
50+
51+
52+
console.log(`"The temperature of the ${variable1} varies on the number of characters a ${variable1} has. \n
53+
So if there are ${dnaLength} characters, the temp will be just right to produce a ${tc}."`)
54+

0 commit comments

Comments
 (0)