Skip to content

Commit 8578887

Browse files
committed
message
1 parent 3d317ca commit 8578887

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
let num = 1001;
1+
let num = 1001.2;
22

33
//Returns 'undefined'.
44
console.log(num.length);
55

66
//Use type conversion to print the length (number of digits) of an integer.
7+
console.log(String(num).length);
8+
//console.log(typeOf num);
79

810
//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-
11+
console.log(String(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 (String(num).includes('.')){
14+
console.log(String(num).length-1);
15+
}else{
16+
console.log(String(num).length);
17+
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33
let language = 'JavaScript';
44

55
//1. Use string concatenation and two slice() methods to print 'JS' from 'JavaScript'
6+
console.log(language.slice(0,1) + language.slice(4.5));
7+
console.log(language.slice(4.5));
68

79
//2. Without using slice(), use method chaining to accomplish the same thing.
10+
console.log(language.replace("Java", "J").replace("Script", "S"));
811

912
//3. Use bracket notation and a template literal to print, "The abbreviation for 'JavaScript' is 'JS'."
10-
13+
console.log(`The abbreviation for ${language} is ${language[0]}${language[4]}.`);
1114
//4. Just for fun, try chaining 3 or more methods together, and then print the result.
15+
console.log(language.toLowerCase().replace("j","q").slice(0,5));
1216

1317
//Part Three section Two
1418

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

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

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,38 @@ let dna = " TCG-TAC-gaC-TAC-CGT-CAG-ACT-TAa-CcA-GTC-cAt-AGA-GCT ";
55
// First, print out the dna strand in it's current state.
66

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+
console.log(dna.trim());
109

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

13-
console.log();
12+
console.log(dna.toUpperCase());
1413

1514
//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.
1615
//Apply these fixes to your code so that console.log(dna) prints the DNA strand in UPPERCASE with no whitespace.
17-
16+
dna = dna.trim().toUpperCase();
1817
console.log(dna);
1918

2019
//Part Two Section Two
2120

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

2423
//1) Replace the gene "GCT" with "AGG", and then print the altered strand.
24+
dnaTwo = dna.replace("GCT", "AGG");
25+
console.log(dnaTwo);
2526

2627
//2) Look for the gene "CAT" with ``indexOf()``. If found print, "CAT gene found", otherwise print, "CAT gene NOT found".
27-
28+
if (dnaTwo.indexOf("CAT") !== (-1)){
29+
console.log("CAT gene found");
30+
}else{
31+
console.log("CAT gene not found");
32+
}
2833
//3) Use .slice() to print out the fifth gene (set of 3 characters) from the DNA strand.
34+
console.log(dnaTwo.slice(16,19));
2935

3036
//4) Use a template literal to print, "The DNA strand is ___ characters long."
37+
console.log(`The new DNA strand is ${dnaTwo.length} characters long.`);
3138

3239
//5) Just for fun, apply methods to ``dna`` and use another template literal to print, 'taco cat'.
40+
let dnaThree = dna.slice(4,7).toLowerCase(dna);
41+
let dnaFour = dna.slice(40,43).toLowerCase(dna);
42+
console.log(`${dnaThree}o ${dnaFour}`);

0 commit comments

Comments
 (0)