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,
undefined rather than 4.
num = 123.45has 5 digits but a length of 6).
numcould be EITHER an integer or a decimal? Add an
if/elsestatement so your code can handle both cases. (Hint: Consider the
Remember, strings are immutable. Consider a string that represents a
strand of DNA:
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.
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.
Let's use string methods to do more work on the DNA strand:
'AGG', and then print the altered strand.
indexOf(). If found print,
'CAT found', otherwise print,
'CAT NOT found'.
slice()to print out the fifth set of 3 characters (called a codon) from the DNA strand.
"The DNA strand is ___ characters long."
dnaand use another template literal to print,
If we want to turn the string
'JS', we might try
However, we can use our cleverness to achieve the same result.
slice()methods to print
slice(), use method chaining to accomplish the same thing.
Some programming languages (like Python) include a
title() method to
return a string with Every Word Capitalized (e.g.
title() method, but that
won't stop us! Use the string methods you know to print
from the string