Skip to content

kellyliang7/string_assignment

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

String Exercises

  1. console.log the first character of a string.

let name = "kelly" name[0]

  1. console.log the length of a string.

let name = "kelly" "kelly".length

  1. console.log the last character of any string.

let str = "pumpkin" console.log(str[str.length -1])

  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'
  1. 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') }

  1. Create a verbing code 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"); }

  1. Create a withoutLast code 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)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published