Giter Site home page Giter Site logo

string_assignment's Introduction

String Exercises

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

  2. console.log the length of a string.

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

  4. Create a code block that takes a single string variable, and returns a copy of the string with the last letter capitalized. For example:

'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)
  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'
  1. Create a withoutLast code block that takes a single string variable, and returns a copy of the string without the last word.

Bonus Questions

  1. Write a code block that adds a "#" to a string if the string has an odd number of characters, otherwise leave it as is. print/log the result

    Examples:

let name = 'taq'  // should log 'taq#'
let name2 ='john' // should log 'john'

  1. Write a code block that prints/logs the 3rd to last characters of a string. If the string is not at least 3 characters long then log an error message.
Hint It should work for strings of any length.

Examples, for variables:

let name1 = 'Taq' // Should log 'Taq'
let sentence = 'He is Taq'// Should log 'Taq'

  1. Write a code block that prints/logs whether a string x starts with a vowel.
Extra

Make it case insensitive


  1. Write a code block that given two strings, str1 and str2, prints/logs a new string with str2 mashed into the middle of str1

Examples:

  • For str1 = 'help' and str2 = 'me'. Your program should log 'hemelp'

  • For str1 = 'hello' and str2 = 'world'. Your program should log 'helworldlo'


  1. Write a code block that prints/logs whether a string x has at least one vowel in it.

Examples:

  • For x = 'taq'. Your program should log 'taq' has a vowel'
  • For x = 'dfghjkl'. Your program should log 'dfghjkl' does not have a vowel'
  • For x = '' Your program should log '' does not have a vowel'
Extra & Hint:
  • Hint: Abstain from using loops. Explore string methods.

  • Extra: Make it case insensitive. So that for x = 'TAQ' it should log 'TAQ' has a vowel


Practice Makes Perfect.

Find at CodingBat more problems/questions to keep practicing. You can pick which ones to do. You can ignore the fact that their solutions are supposed to be written in Java, I trust you that you can write a solution code block in JavaScript. Create a file codingBatStrings.js copy and paste the problem statement as a comment, underneath write your solution.

Remember: This are bonuses and extra points. You don't have to do them but if you do, you will just get better.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.