'JavaScript'[8] = 'p'
"Wonderful".length = 9
There's no code snippet for this one, just try it on your own with old-fashioned pen and paper!
length
method returns how many characters are in a string. However, the method will NOT give us the length of a number. If num = 1001
, num.length
returns undefined
rather than 4.let num = 1001;
num
could be EITHER an integer or a decimal? Add an if/else
statement so your code can handle both cases. (Hint: Consider the indexOf()
or includes()
string methods).1if (String(num).includes('.')){
2console.log(String(num).length-1);
3} else {
4console.log(String(num).length);
5}
dna = " TCG-TAC-gaC-TAC-CGT-CAG-ACT-TAa-CcA-GTC-cAt-AGA-GCT "
. There are some typos in the string that we would like to fix:trim()
method to remove the leading and trailing whitespace, and then print the results.1let dna = " TCG-TAC-gaC-TAC-CGT-CAG-ACT-TAa-CcA-GTC-cAt-AGA-GCT ";
2let newString = dna.trim();
3console.log(newString);
console.log(dna)
after applying the methods, the original, flawed string is displayed. To fix this, you need to reassign the changes back to dna
. Apply these fixes to your code so that console.log(dna)
prints the DNA strand in UPPERCASE with no whitespace.1let dna = " TCG-TAC-gaC-TAC-CGT-CAG-ACT-TAa-CcA-GTC-cAt-AGA-GCT ";
2dna = dna.trim().toUpperCase();
3console.log(dna);
'GCT'
with 'AGG'
, and then print the altered Sstrand.1dna = dna.replace('GCT','AGG');
2console.log(dna);
slice()
to print out the fifth set of 3 characters (called a codon) from the DNA strand.console.log(dna.slice(16,19));
dna
and use another template literal to print, 'taco cat'
.console.log(`${dna.slice(4,7).toLowerCase()}o ${dna.slice(dna.indexOf('CAT'),dna.indexOf('CAT')+3).toLowerCase()}`);
'JavaScript'
into 'JS'
, we might try .remove()
. Unfortunately, there is no such method in JavaScript. However, we can use our cleverness to achieve the same result.slice()
methods to print 'JS'
from 'JavaScript'
.1let language = 'JavaScript';
2console.log(language.slice(0,1)+language.slice(4,5));
"The abbreviation for 'JavaScript' is 'JS'."
console.log(`The abbreviation for '${language}' is '${initials}'.`)