Skip to content

Commit 44753df

Browse files
committed
parts 1/2/3
1 parent d50f7f7 commit 44753df

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ let num = 1001;
44
console.log(num.length);
55

66
//Use type conversion to print the length (number of digits) of an integer.
7-
7+
num = String(1001)
8+
console.log(num.length)
89
//Follow up: Print the number of digits in a DECIMAL value (e.g. num = 123.45 has 5 digits but a length of 6).
9-
10+
num = String(123.45)
11+
console.log(num.length - 1)
1012
//Experiment! What if num could be EITHER an integer or a decimal? Add an if/else statement so your code can handle both cases.
13+
if (num.includes('.')) {
14+
console.log(num.length - 1)
15+
} else {
16+
console.log(num.length)
17+
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
let language = 'JavaScript';
44

55
//1. Use string concatenation and two slice() methods to print 'JS' from 'JavaScript'
6-
6+
console.log((language.slice(0,1))+(language.slice(4,5)))
77
//2. Without using slice(), use method chaining to accomplish the same thing.
8-
8+
console.log(language.replace("JavaScript", "js").toUpperCase())
99
//3. Use bracket notation and a template literal to print, "The abbreviation for 'JavaScript' is 'JS'."
10-
10+
console.log(`The abbreviation for '${language}' is '${language[0]}${language[4]}'`)
1111
//4. Just for fun, try chaining 3 or more methods together, and then print the result.
12-
12+
console.log(language.slice(0,4).replace("Java", "COFFEE").toLowerCase())
1313
//Part Three section Two
1414

1515
//1. Use the string methods you know to print 'Title Case' from the string 'title case'.
1616

1717
let notTitleCase = 'title case';
18+
console.log(notTitleCase.replace("t","T").replace("c","C"))

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,35 @@
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.
88

9-
console.log(/* Your code here. */);
9+
console.log(dna.trim());
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-
17+
dna = dna.trim().toUpperCase()
1818
console.log(dna);
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.
25-
25+
console.log(dnaTwo.replace("GCT", "AGG"))
2626
//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") === -1) {
28+
console.log("CAT gene NOT found")
29+
} else {
30+
console.log("CAT gene found")
31+
}
2832
//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))
3034
//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.`)
3236
//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(20,22).toLowerCase()}${dna.slice(0,1).toLowerCase()}`)

0 commit comments

Comments
 (0)