{"id":450,"date":"2021-01-04T19:33:24","date_gmt":"2021-01-04T19:33:24","guid":{"rendered":"https:\/\/avantutor.com\/blog\/?p=450"},"modified":"2021-01-04T19:34:37","modified_gmt":"2021-01-04T19:34:37","slug":"10-simple-javascript-string-exercises","status":"publish","type":"post","link":"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/","title":{"rendered":"10 Simple JavaScript String Exercises"},"content":{"rendered":"\n<p>Practice your JavaScript skills by completing these string related exercises that I personally picked off codewars.<\/p>\n\n\n\n<p>While the focus is on JavaScript strings most of these exercises also touch on loops and arrays. <\/p>\n\n\n\n<p>I tried to pick relatively easy JavaScript String exercises but could be one or two that are a little bit more challenging. These are meant for complete coding newbs! Be aware.<\/p>\n\n\n\n<p>I have created two versions of this JavaScript string exercise set. One is the embedded compiler version and the other is plain text.<\/p>\n\n\n\n<p>With that said, enjoy!  <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Embedded Compiler Version<\/h2>\n\n\n\n<iframe loading=\"lazy\" src=\"https:\/\/paiza.io\/projects\/e\/c-PsrMGJv0Gj57dEX6e7-w?theme=twilight\" width=\"100%\" height=\"500\" scrolling=\"no\" seamless=\"seamless\"><\/iframe>\n\n\n\n<h2 class=\"wp-block-heading\">Plain Text Version<\/h2>\n\n\n\n<p class=\"has-large-font-size\"><strong>Exercise 1<\/strong><\/p>\n\n\n\n<p>Complete the function that receives as input a string, and produces outputs according to the following table:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Input<\/strong><\/td><td><strong>Output<\/strong><\/td><\/tr><tr><td>&#8220;Jabroni&#8221;<\/td><td>&#8220;Patron Tequila&#8221;<\/td><\/tr><tr><td>&#8220;School Counselor&#8221;<\/td><td>&#8220;Anything with Alcohol&#8221;<\/td><\/tr><tr><td>&#8220;Programmer&#8221;<\/td><td>&#8220;Hipster Craft Beer&#8221;<\/td><\/tr><tr><td>&#8220;Bike Gang Member&#8221;<\/td><td>&#8220;Moonshine&#8221;<\/td><\/tr><tr><td>&#8220;Politician&#8221;<\/td><td>&#8220;Your tax dollars&#8221;<\/td><\/tr><tr><td>&#8220;Rapper&#8221;<\/td><td>&#8220;Cristal&#8221;<\/td><\/tr><tr><td><em>anything else<\/em><\/td><td>&#8220;Beer&#8221;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Note:<\/strong>&nbsp;<em>anything else<\/em>&nbsp;is the default case: if the input to the function is not any of the values in the table, then the return value should be&nbsp;&#8220;Beer&#8221;.<\/p>\n\n\n\n<p>Make sure you cover the cases where certain words do not show up with correct capitalization. For example, the input&nbsp;&#8220;pOLitiCIaN&#8221;&nbsp;should still return&nbsp;&#8220;Your tax dollars&#8221;<\/p>\n\n\n\n<p class=\"has-large-font-size\"><strong>Exercise 2<\/strong><\/p>\n\n\n\n<p><strong>Write a function that returns a sequence (index begins with 1) of all the even characters from a string. If the string is smaller than two characters or longer than 100 characters, the function should return &#8220;invalid string&#8221;.<\/strong><\/p>\n\n\n\n<p><strong>For example:<\/strong><\/p>\n\n\n\n<p>&#8220;abcdefghijklm&#8221; &#8211;&gt; [&#8220;b&#8221;, &#8220;d&#8221;, &#8220;f&#8221;, &#8220;h&#8221;, &#8220;j&#8221;, &#8220;l&#8221;]<\/p>\n\n\n\n<p>&#8220;a&#8221; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8211;&gt; &#8220;invalid string&#8221;<\/p>\n\n\n\n<p class=\"has-large-font-size\"><strong>Exercise <\/strong>3<\/p>\n\n\n\n<p>The company you work for has just been awarded a contract to build a payment gateway. In order to help move things along, you have volunteered to create a function that will take a float and return (IN STRING FORMAT) the amount formatting in dollars and cents.<\/p>\n\n\n\n<p>39.99 becomes $39.99<\/p>\n\n\n\n<p>The rest of your team will make sure that the argument is sanitized before being passed to your function although you will need to account for adding trailing zeros if they are missing (though you won&#8217;t have to worry about a dangling period).<\/p>\n\n\n\n<p>Examples:<\/p>\n\n\n\n<p>3 needs to become $3.00<\/p>\n\n\n\n<p>3.1 needs to become $3.10<\/p>\n\n\n\n<p>Good luck! Your team knows they can count on you!<\/p>\n\n\n\n<p class=\"has-large-font-size\"><strong>Exercise 4<\/strong><\/p>\n\n\n\n<p><strong>In this Kata, you will be given two strings&nbsp;a&nbsp;and&nbsp;b&nbsp;and your task will be to return the characters that are not common in the two strings.<\/strong><\/p>\n\n\n\n<p><strong>For example:<\/strong><\/p>\n\n\n\n<p>solve(&#8220;xyab&#8221;,&#8221;xzca&#8221;) = &#8220;ybzc&#8221;&nbsp;<\/p>\n\n\n\n<p>&#8211;The first string has &#8216;yb&#8217; which is not in the second string.&nbsp;<\/p>\n\n\n\n<p>&#8211;The second string has &#8216;zc&#8217; which is not in the first string.&nbsp;<\/p>\n\n\n\n<p><strong>Notice also that you return the characters from the first string concatenated with those from the second string.<\/strong><\/p>\n\n\n\n<p><strong>More examples in the tests cases.<\/strong><\/p>\n\n\n\n<p><strong>Good luck!<\/strong><\/p>\n\n\n\n<p class=\"has-large-font-size\"><strong>Exercise 5<\/strong><\/p>\n\n\n\n<p>Complete the solution so that it reverses the string passed into it.<\/p>\n\n\n\n<p>&#8216;world&#8217;&nbsp; =&gt;&nbsp; &#8216;dlrow&#8217;<\/p>\n\n\n\n<p class=\"has-large-font-size\"><strong>Exercise 6<\/strong><\/p>\n\n\n\n<p><strong>You receive the name of a city as a string, and you need to return a string that shows how many times each letter shows up in the string by using asterisks (*).<\/strong><\/p>\n\n\n\n<p><strong>For example:<\/strong><\/p>\n\n\n\n<p>&#8220;Chicago&#8221;&nbsp; &#8211;&gt;&nbsp; &#8220;c:**,h:*,i:*,a:*,g:*,o:*&#8221;<\/p>\n\n\n\n<p><strong>As you can see, the letter&nbsp;c&nbsp;is shown only once, but with 2 asterisks.<\/strong><\/p>\n\n\n\n<p><strong>The return string should include&nbsp;only the letters&nbsp;(not the dashes, spaces, apostrophes, etc). There should be no spaces in the output, and the different letters are separated by a comma (,) as seen in the example above.<\/strong><\/p>\n\n\n\n<p><strong>Note that the return string must list the letters in order of their first appearance in the original string.<\/strong><\/p>\n\n\n\n<p><strong>More examples:<\/strong><\/p>\n\n\n\n<p>&#8220;Bangkok&#8221;&nbsp; &nbsp; &#8211;&gt;&nbsp; &#8220;b:*,a:*,n:*,g:*,k:**,o:*&#8221;<\/p>\n\n\n\n<p>&#8220;Las Vegas&#8221;&nbsp; &#8211;&gt;&nbsp; &#8220;l:*,a:**,s:**,v:*,e:*,g:*&#8221;<\/p>\n\n\n\n<p><strong>Have fun! \ud83d\ude09<\/strong><\/p>\n\n\n\n<p class=\"has-large-font-size\"><strong>Exercise 7<\/strong><\/p>\n\n\n\n<p><strong>Complete the solution so that it reverses all of the words within the string passed in.<\/strong><\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>reverseWords(&#8220;The greatest victory is that which requires no battle&#8221;)<\/p>\n\n\n\n<p><em>\/\/ should return &#8220;battle no requires which that is victory greatest The&#8221;<\/em><\/p>\n\n\n\n<p class=\"has-large-font-size\"><strong>Exercise <\/strong>8<\/p>\n\n\n\n<p>Return the number (count) of vowels in the given string.<\/p>\n\n\n\n<p>We will consider&nbsp;a, e, i, o, u&nbsp;as vowels for this Kata (but not&nbsp;y).<\/p>\n\n\n\n<p>The input string will only consist of lower case letters and\/or spaces.<\/p>\n\n\n\n<p class=\"has-large-font-size\"><strong>Exercise 9<\/strong><\/p>\n\n\n\n<p>Create a function which answers the question &#8220;Are you playing banjo?&#8221;.<br>If your name starts with the letter &#8220;R&#8221; or lower case &#8220;r&#8221;, you are playing banjo!<\/p>\n\n\n\n<p>The function takes a name as its only argument, and returns one of the following strings:<\/p>\n\n\n\n<p>name + &#8221; plays banjo&#8221;&nbsp;<\/p>\n\n\n\n<p>name + &#8221; does not play banjo&#8221;<\/p>\n\n\n\n<p>Names given are always valid strings.<\/p>\n\n\n\n<p class=\"has-large-font-size\"><strong>Exercise 10<\/strong><\/p>\n\n\n\n<p>Given a string, return true if the first instance of &#8220;x&#8221; in the string is immediately followed by the string &#8220;xx&#8221;.<\/p>\n\n\n\n<p>tripleX(&#8220;abraxxxas&#8221;) \u2192 true<\/p>\n\n\n\n<p>tripleX(&#8220;xoxotrololololololoxxx&#8221;) \u2192 false<\/p>\n\n\n\n<p>tripleX(&#8220;softX kitty, warm kitty, xxxxx&#8221;) \u2192 true<\/p>\n\n\n\n<p>tripleX(&#8220;softx kitty, warm kitty, xxxxx&#8221;) \u2192 false<\/p>\n\n\n\n<p>Note :<\/p>\n\n\n\n<ul><li>capital X&#8217;s do not count as an occurrence of &#8220;x&#8221;.<\/li><li>if there are no &#8220;x&#8221;&#8216;s then return false<\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Practice your JavaScript skills by completing these string related exercises that I personally picked off codewars. While the focus is on JavaScript strings most of these exercises also touch on loops and arrays. I tried to pick relatively easy JavaScript&#8230; <a class=\"more-link\" href=\"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[21],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>10 Simple JavaScript String Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding<\/title>\n<meta name=\"description\" content=\"Practice your JavaScript (string) skills by completing these easy string related exercises that I personally picked off codewars.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"10 Simple JavaScript String Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\" \/>\n<meta property=\"og:description\" content=\"Practice your JavaScript (string) skills by completing these easy string related exercises that I personally picked off codewars.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/\" \/>\n<meta property=\"og:site_name\" content=\"AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-04T19:33:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-01-04T19:34:37+00:00\" \/>\n<meta name=\"author\" content=\"avansardar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"avansardar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/\",\"url\":\"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/\",\"name\":\"10 Simple JavaScript String Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\",\"isPartOf\":{\"@id\":\"https:\/\/avantutor.com\/blog\/#website\"},\"datePublished\":\"2021-01-04T19:33:24+00:00\",\"dateModified\":\"2021-01-04T19:34:37+00:00\",\"author\":{\"@id\":\"https:\/\/avantutor.com\/blog\/#\/schema\/person\/3a1820bcdd71870ace675436f371be9e\"},\"description\":\"Practice your JavaScript (string) skills by completing these easy string related exercises that I personally picked off codewars.\",\"breadcrumb\":{\"@id\":\"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/avantutor.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"10 Simple JavaScript String Exercises\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/avantutor.com\/blog\/#website\",\"url\":\"https:\/\/avantutor.com\/blog\/\",\"name\":\"AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\",\"description\":\"Looking for expert advice on how to improve your coding skills? The AvanTutor blog provides a wealth of resources and insights to help you become a better programmer. Our experienced tutors share tips and tricks for mastering popular programming languages such as Java, and JavaScript, as well as insights into the latest trends in software development. With regular updates and engaging content, the AvanTutor blog is your go-to resource for all things coding.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/avantutor.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/avantutor.com\/blog\/#\/schema\/person\/3a1820bcdd71870ace675436f371be9e\",\"name\":\"avansardar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/avantutor.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/81392f2a2c93b7b1c7479ed6b4115f02?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/81392f2a2c93b7b1c7479ed6b4115f02?s=96&d=mm&r=g\",\"caption\":\"avansardar\"},\"url\":\"https:\/\/avantutor.com\/blog\/author\/avansardar\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"10 Simple JavaScript String Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","description":"Practice your JavaScript (string) skills by completing these easy string related exercises that I personally picked off codewars.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/","og_locale":"en_US","og_type":"article","og_title":"10 Simple JavaScript String Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","og_description":"Practice your JavaScript (string) skills by completing these easy string related exercises that I personally picked off codewars.","og_url":"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/","og_site_name":"AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","article_published_time":"2021-01-04T19:33:24+00:00","article_modified_time":"2021-01-04T19:34:37+00:00","author":"avansardar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"avansardar","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/","url":"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/","name":"10 Simple JavaScript String Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","isPartOf":{"@id":"https:\/\/avantutor.com\/blog\/#website"},"datePublished":"2021-01-04T19:33:24+00:00","dateModified":"2021-01-04T19:34:37+00:00","author":{"@id":"https:\/\/avantutor.com\/blog\/#\/schema\/person\/3a1820bcdd71870ace675436f371be9e"},"description":"Practice your JavaScript (string) skills by completing these easy string related exercises that I personally picked off codewars.","breadcrumb":{"@id":"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/avantutor.com\/blog\/10-simple-javascript-string-exercises\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/avantutor.com\/blog\/"},{"@type":"ListItem","position":2,"name":"10 Simple JavaScript String Exercises"}]},{"@type":"WebSite","@id":"https:\/\/avantutor.com\/blog\/#website","url":"https:\/\/avantutor.com\/blog\/","name":"AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","description":"Looking for expert advice on how to improve your coding skills? The AvanTutor blog provides a wealth of resources and insights to help you become a better programmer. Our experienced tutors share tips and tricks for mastering popular programming languages such as Java, and JavaScript, as well as insights into the latest trends in software development. With regular updates and engaging content, the AvanTutor blog is your go-to resource for all things coding.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/avantutor.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/avantutor.com\/blog\/#\/schema\/person\/3a1820bcdd71870ace675436f371be9e","name":"avansardar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/avantutor.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/81392f2a2c93b7b1c7479ed6b4115f02?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/81392f2a2c93b7b1c7479ed6b4115f02?s=96&d=mm&r=g","caption":"avansardar"},"url":"https:\/\/avantutor.com\/blog\/author\/avansardar\/"}]}},"_links":{"self":[{"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/posts\/450"}],"collection":[{"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/comments?post=450"}],"version-history":[{"count":1,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/posts\/450\/revisions"}],"predecessor-version":[{"id":451,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/posts\/450\/revisions\/451"}],"wp:attachment":[{"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/media?parent=450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/categories?post=450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/tags?post=450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}