{"id":418,"date":"2020-01-28T16:55:25","date_gmt":"2020-01-28T16:55:25","guid":{"rendered":"https:\/\/avantutor.com\/blog\/?p=418"},"modified":"2023-02-26T21:48:44","modified_gmt":"2023-02-26T21:48:44","slug":"10-simple-javascript-for-loop-exercises","status":"publish","type":"post","link":"https:\/\/avantutor.com\/blog\/10-simple-javascript-for-loop-exercises\/","title":{"rendered":"10 Simple Javascript For-Loop Exercises"},"content":{"rendered":"\n<p>Here 10 simple javascript For-Loop Exercises to test your introductory-level understanding of Javascript For-Loops. Use for-loops in all of your solutions below. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Scroll down to the bottom of the page for an embedded compiler. <\/h3>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 1)<\/h2>\n\n\n\n<p>Get the sum of two arrays\u2026actually the sum of all their elements. <br>P.S. Each array includes only integer numbers. Output is a number too.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let arr_1 = &#91;3, 5, 22, 5,  7,  2,  45, 75, 89, 21, 2]; \/\/ --> 276\nlet arr_2 = &#91;9, 2, 42, 55, 71, 22, 4,  5,  90, 25, 26]; \/\/ --> 351\n\/\/ Example output: \n\/\/ 276 + 351 = 627<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 2)<\/h2>\n\n\n\n<p>Using a for loop print all even numbers up to and including n. Don\u2019t include 0.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let n1 = 22; \n\/\/ Example output: \n\/\/ 2 4 6 8 10 12 14 16 18 20 22 OR each item on a new line\n <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 3)<\/h2>\n\n\n\n<p>Using a for loop output the elements in reverse order <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let arr = &#91;43, \"what\", 9, true, \"cannot\", false, \"be\", 3, true];\n\/\/ Example output: \n\/\/ true 3.5  be  false cannot  true 9 what 43 OR each item on a new line<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 4)<\/h2>\n\n\n\n<p>Given two arrays of integers. Add up each element in the same position and  <br>create a new array containing the sum of each pair. Assume both arrays are of the same length.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> \nlet arr_3   = &#91;4, 6, 7];\nlet arr_4    = &#91;8, 1, 9];\n\/\/ Example output: \n\/\/ &#91;12, 7, 16]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 5)<\/h2>\n\n\n\n<p>Given a string change the every second letter to an uppercase  \u2018Z\u2019. Assume <br>there are no space. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let str1 = \"javascript\";  \n\/\/ Example output: \n\/\/ jZvZsZrZpZ OR each letter on a new line\n\/\/ HINT: You can use  if((i+1) % 2 == 0) to check for even indexes <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 6)<\/h2>\n\n\n\n<p>Check if a string contains the letter \u201cy\u201d. Print \u201cyes\u201d if it does and \u201cno\u201d if it does not.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let str2 = \"don\u2019t know why\";\n\/\/ Example output: \n\/\/ \u201cyes\u201d <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 7)<\/h2>\n\n\n\n<p>Given a number n Calculate the factorial of the number <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let n2 = 4; \/\/  4 * 3 * 2 * 1 = 24\n\/\/ Example output:\n\/\/ 24<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 8)<\/h2>\n\n\n\n<p>Write a program that will allow someone to guess a four digit pin exactly 4 <br>times. If the user guesses the number correctly. It prints  \u201cThat was <br>correct!\u201d Otherwise it will print \u201cSorry that was wrong.\u201d Program stops after  the 4th attempt of if they got it right. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let pin = 0704;\n\/\/ Example output:\n\/\/ Please make your guess: \n\/\/ 4544 \n\/\/ Sorry that was wrong.\n\/\/ Please make your guess: \n\/\/ 4444\n\/\/ Sorry that was wrong.\n\/\/ Please make your guess: \n\/\/ 0704\n\/\/ That was correct!<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 9)<\/h2>\n\n\n\n<p>Write a program that will check if two strings are palindromes. A palindrome is a word that spells the same forward and backward. <br>Palindrome: a word, phrase, or sequence that reads the same backward as <br>forward, e.g., madam or nurses run.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let str3 = \"racecar\";\nlet str4 = \"Java\";\n\/\/ Example output:\n\/\/ string1 palindrome?: \n\/\/ Yes \n\/\/ string2 palindrome?: \n\/\/ No <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 10)<\/h2>\n\n\n\n<p>This is a code wars kata. click here to train on \u201cGrasshopper \u2013 Summation\u201d on <br>code wars. Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater than 0.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let num1 = 2; \nlet num2 = 8; \n\/\/ Example output: \n\/\/ 1 + 2 = 3\n\/\/ 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36 <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>EMBEDDED COMPILER<\/strong><\/h2>\n\n\n\n<iframe loading=\"lazy\" src=\"https:\/\/paiza.io\/projects\/e\/pKpjxMj_grEg4h0OOBpcUw?theme=eclipse\" width=\"100%\" height=\"500\" scrolling=\"no\" seamless=\"seamless\"><\/iframe>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here 10 simple javascript For-Loop Exercises to test your introductory-level understanding of Javascript For-Loops. Use for-loops in all of your solutions below. Scroll down to the bottom of the page for an embedded compiler. Exercise 1) Get the sum of&#8230; <a class=\"more-link\" href=\"https:\/\/avantutor.com\/blog\/10-simple-javascript-for-loop-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":[24,60,11],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>10 Simple Javascript For-Loop Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding<\/title>\n<meta name=\"description\" content=\"Here 10 simple javascript For-Loop Exercises to test your introductory level understanding of Javascript For-Loops. Use for-loops in all of your solutions below. Use the embedded compiler below to test your solutions.\" \/>\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-for-loop-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 For-Loop Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\" \/>\n<meta property=\"og:description\" content=\"Here 10 simple javascript For-Loop Exercises to test your introductory level understanding of Javascript For-Loops. Use for-loops in all of your solutions below. Use the embedded compiler below to test your solutions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/avantutor.com\/blog\/10-simple-javascript-for-loop-exercises\/\" \/>\n<meta property=\"og:site_name\" content=\"AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-28T16:55:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-26T21:48:44+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=\"2 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-for-loop-exercises\/\",\"url\":\"https:\/\/avantutor.com\/blog\/10-simple-javascript-for-loop-exercises\/\",\"name\":\"10 Simple Javascript For-Loop Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\",\"isPartOf\":{\"@id\":\"https:\/\/avantutor.com\/blog\/#website\"},\"datePublished\":\"2020-01-28T16:55:25+00:00\",\"dateModified\":\"2023-02-26T21:48:44+00:00\",\"author\":{\"@id\":\"https:\/\/avantutor.com\/blog\/#\/schema\/person\/3a1820bcdd71870ace675436f371be9e\"},\"description\":\"Here 10 simple javascript For-Loop Exercises to test your introductory level understanding of Javascript For-Loops. Use for-loops in all of your solutions below. Use the embedded compiler below to test your solutions.\",\"breadcrumb\":{\"@id\":\"https:\/\/avantutor.com\/blog\/10-simple-javascript-for-loop-exercises\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/avantutor.com\/blog\/10-simple-javascript-for-loop-exercises\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/avantutor.com\/blog\/10-simple-javascript-for-loop-exercises\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/avantutor.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"10 Simple Javascript For-Loop 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 For-Loop Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","description":"Here 10 simple javascript For-Loop Exercises to test your introductory level understanding of Javascript For-Loops. Use for-loops in all of your solutions below. Use the embedded compiler below to test your solutions.","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-for-loop-exercises\/","og_locale":"en_US","og_type":"article","og_title":"10 Simple Javascript For-Loop Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","og_description":"Here 10 simple javascript For-Loop Exercises to test your introductory level understanding of Javascript For-Loops. Use for-loops in all of your solutions below. Use the embedded compiler below to test your solutions.","og_url":"https:\/\/avantutor.com\/blog\/10-simple-javascript-for-loop-exercises\/","og_site_name":"AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","article_published_time":"2020-01-28T16:55:25+00:00","article_modified_time":"2023-02-26T21:48:44+00:00","author":"avansardar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"avansardar","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/avantutor.com\/blog\/10-simple-javascript-for-loop-exercises\/","url":"https:\/\/avantutor.com\/blog\/10-simple-javascript-for-loop-exercises\/","name":"10 Simple Javascript For-Loop Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","isPartOf":{"@id":"https:\/\/avantutor.com\/blog\/#website"},"datePublished":"2020-01-28T16:55:25+00:00","dateModified":"2023-02-26T21:48:44+00:00","author":{"@id":"https:\/\/avantutor.com\/blog\/#\/schema\/person\/3a1820bcdd71870ace675436f371be9e"},"description":"Here 10 simple javascript For-Loop Exercises to test your introductory level understanding of Javascript For-Loops. Use for-loops in all of your solutions below. Use the embedded compiler below to test your solutions.","breadcrumb":{"@id":"https:\/\/avantutor.com\/blog\/10-simple-javascript-for-loop-exercises\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/avantutor.com\/blog\/10-simple-javascript-for-loop-exercises\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/avantutor.com\/blog\/10-simple-javascript-for-loop-exercises\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/avantutor.com\/blog\/"},{"@type":"ListItem","position":2,"name":"10 Simple Javascript For-Loop 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\/418"}],"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=418"}],"version-history":[{"count":5,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/posts\/418\/revisions"}],"predecessor-version":[{"id":448,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/posts\/418\/revisions\/448"}],"wp:attachment":[{"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/media?parent=418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/categories?post=418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/tags?post=418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}