Skip to content

Commit eedd5ea

Browse files
committed
CH7 HW V1
1 parent 7dc34e1 commit eedd5ea

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
let num = 1001;
22

3-
//Returns 'undefined'.
3+
//Returns 'undefined'. DOES NOT GIVE LENGTH OF A NUMBER
44
console.log(num.length);
55

66
//Use type conversion to print the length (number of digits) of an integer.
77

8+
let stringedNumber = num.toString();
9+
let lengthOfNum = stringedNumber.length;
10+
console.log(stringedNumber.length);
11+
12+
813
//Follow up: Print the number of digits in a DECIMAL value (e.g. num = 123.45 has 5 digits but a length of 6).
14+
//THE PERIOD COUNTS IN THE LENGTH and must be modified to remove the period
15+
let decVal = 1234.56
16+
let decValString = decVal.toString();
17+
let lengthOfD = decVal.length;
18+
console.log(decValString.length);
19+
20+
let decValWithout = decValString.replace('.', '');//removed the period from a string
21+
console.log(decValWithout.length);//prints string excluding period
22+
923

1024
//Experiment! What if num could be EITHER an integer or a decimal? Add an if/else statement so your code can handle both cases.
25+
if (String(num).includes('.')){
26+
console.log(String(num).length-1);
27+
} else {
28+
console.log(String(num).length);
29+
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,34 @@ let language = 'JavaScript';
44

55
//1. Use string concatenation and two slice() methods to print 'JS' from 'JavaScript'
66

7+
console.log(language.slice(0,1));//could also make a variable for j and s and then add them together
8+
console.log(language.slice(4,5));//you would could add them together using ${} or print the two variables
9+
10+
11+
console.log(language.slice(0,1) + language.slice(4,5));
12+
713
//2. Without using slice(), use method chaining to accomplish the same thing.
814

15+
console.log(language.substring(0,1));
16+
console.log(language.substring(4,5));
17+
18+
let initials = (language.substring(0,1) + language.slice(4,5));
19+
console.log(initials);
20+
921
//3. Use bracket notation and a template literal to print, "The abbreviation for 'JavaScript' is 'JS'."
22+
//kind of confused here idk why the brackets keep printing?
23+
//is the solution wrong? or mu understanding of bracket notation is not correct?
24+
console.log("The abbreviation for [" + language + "] is [" + initials + "].");
1025

1126
//4. Just for fun, try chaining 3 or more methods together, and then print the result.
1227

28+
let forFun = (language.slice(0,1) + language.substring(4,5) + ", " + language.length + ", " + language.toLowerCase());
29+
console.log(forFun);
1330
//Part Three section Two
1431

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

1734
let notTitleCase = 'title case';
35+
let realCase = notTitleCase.replace("title case", "Tital Case");
36+
37+
console.log(realCase);

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,46 @@
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+
console.log(dna);
67

78
//1) Use the .trim() method to remove the leading and trailing whitespace, then print the result.
89

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

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

13-
console.log();
14+
console.log(dna.toLocaleUpperCase());
1415

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

19+
dna = dna.trim().toLocaleUpperCase();
1820
console.log(dna);
1921

2022
//Part Two Section Two
2123

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

2426
//1) Replace the gene "GCT" with "AGG", and then print the altered strand.
27+
dnaTwo = dnaTwo.replace('GCT','AGG');
28+
console.log(dnaTwo);
2529

2630
//2) Look for the gene "CAT" with ``indexOf()``. If found print, "CAT gene found", otherwise print, "CAT gene NOT found".
2731

32+
if (dnaTwo.indexOf('CAT') !== -1) {
33+
console.log("CAT FOUND");
34+
} else {
35+
console.log("CAT NOT found");
36+
}
2837
//3) Use .slice() to print out the fifth gene (set of 3 characters) from the DNA strand.
2938

39+
console.log(dnaTwo.slice(16,19));
40+
3041
//4) Use a template literal to print, "The DNA strand is ___ characters long."
3142

43+
console.log(`The DNA strand is ${dnaTwo.length} characters long.`);
44+
3245
//5) Just for fun, apply methods to ``dna`` and use another template literal to print, 'taco cat'.
46+
let food = "taco cat";
47+
console.log(dna.toLowerCase);
48+
console.log(`oh i just can't wait to eat a ${food}`);

0 commit comments

Comments
 (0)