- console.log the first character of a string.
let name = "kelly" name[0]
- console.log the length of a string.
let name = "kelly" "kelly".length
- console.log the last character of any string.
let str = "pumpkin" console.log(str[str.length -1])
- Create a code block that takes a single string variable, and returns a copy of the string with the last letter capitalized. For example:
let str = "coffee" str.slice(str[0], str.length -1) + str.slice(str.length -1).toUpperCase()
'jimmy'
// => 'jimmY'- Create a drEvil code block that will take a single number variable, and log the ' dollars', your code block should add '(pinky)' at the end of the amount if it's 1 million. For example:
let amount = 10
// => 10 dollars
let amount = 1000000
// => 1000000 dollars (pinky)let amount = 1000000 if(amount == 1000000){ console.log(amount + ' dollars' + ' (pinky)'); } else { console.log(amount + ' dollars') }
- Create a
verbingcode block. It should take a single string variable. If its length is at least 3, it should add 'ing' to its end, unless it already ends in 'ing', in which case it should add 'ly' instead. If the string length is less than 3, it should leave it unchanged. For example:
verbing('box')
// => 'boxing'
verbing('train')
// => 'training'
verbing('swimming')
// => 'swimmingly'
verbing('go')
// => 'go'let str = "box" if (str.length >= 3){ str.slice(str[0], str.length) console.log(str + "ing"); }
- Create a
withoutLastcode block that takes a single string variable, and returns a copy of the string without the last
let withoutLast = "Brooklyn" withoutLast.slice(withoutLast[0],withoutLast.length -1)