<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: TakDevelops</title>
    <description>The latest articles on DEV Community by TakDevelops (@takdevelops).</description>
    <link>https://dev.to/takdevelops</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F830442%2Fe7c8103d-02b0-4e35-bb16-9eef77fb660f.jpeg</url>
      <title>DEV Community: TakDevelops</title>
      <link>https://dev.to/takdevelops</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/takdevelops"/>
    <language>en</language>
    <item>
      <title>Career Pivot into Development Journal, Day 6: JS Practice 5 – sumAll.js</title>
      <dc:creator>TakDevelops</dc:creator>
      <pubDate>Thu, 31 Mar 2022 04:47:39 +0000</pubDate>
      <link>https://dev.to/takdevelops/career-pivot-into-development-journal-day-6-js-practice-5-sumalljs-384c</link>
      <guid>https://dev.to/takdevelops/career-pivot-into-development-journal-day-6-js-practice-5-sumalljs-384c</guid>
      <description>&lt;p&gt;&lt;em&gt;It's been a few days, I've been quite busy with work so I had to prioritize that first, but I'm so happy I can get back to programming again! :D Moving on to the next exercise...&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Understanding the problem
&lt;/h2&gt;

&lt;p&gt;In this exercise, I have to create a function that takes two numbers as parameters, and sums all of the numbers between those two numbers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Plan
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Does the program have a UI? What will it look like? What functionality will it have? &lt;strong&gt;&lt;em&gt;No UI&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;What are the inputs? Will the user enter in data or will you get it from somewhere else? &lt;strong&gt;&lt;em&gt;Two numbers in the function parameter. The numbers will be entered when calling the function&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;What are the outputs? &lt;strong&gt;&lt;em&gt;A number, which is the sum of all incremental whole numbers between the two parameters&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Pseudocode
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Declare a function that takes two parameters, `startNum` and `endNum`. Name it `sumAll`

Create a loop where the initialiser = `startNum` and the condition = `endNum`. Increment the loop.

Declare a variable `sum` and set it equal to 0

Concatenate `i` with `i` and store it in the variable `sum`

Return `sum`

Call the function `sumAll(startNum, endNum)`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Divide &amp;amp; Conquer
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Declare a function that takes two parameters, &lt;code&gt;startNum&lt;/code&gt; and &lt;code&gt;endNum&lt;/code&gt;. Name it &lt;code&gt;sumAll&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sumAll = function(startNum, endNum) {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create a loop where the initialiser = &lt;code&gt;startNum&lt;/code&gt; and the condition = &lt;code&gt;endNum&lt;/code&gt;. Increment the loop.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sumAll = function(startNum, endNum) {
    for (let i = startNum; i &amp;lt;= endNum; i++) {
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Declare a variable &lt;code&gt;sum&lt;/code&gt; and set it equal to 0
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sumAll = function(startNum, endNum) {
    let sum = 0;
    for (let i = startNum; i &amp;lt;= endNum; i++) {}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Concatenate &lt;code&gt;i&lt;/code&gt; with &lt;code&gt;i&lt;/code&gt; and store it in the variable &lt;code&gt;sum&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sumAll = function(startNum, endNum) {
    let sum = 0;
    for (let i = startNum; i &amp;lt;= endNum; i++) {
        sum += i;
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Return &lt;code&gt;sum&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sumAll = function(startNum, endNum) {
    let sum = 0;
    for (let i = startNum; i &amp;lt;= endNum; i++) {
        sum += i;
    }
    return sum;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Call the function &lt;code&gt;sumAll(startNum, endNum)&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sumAll = function(startNum, endNum) {
    let sum = 0;
    for (let i = startNum; i &amp;lt;= endNum; i++) {
        sum += i;
    }
    return sum;
};

sumAll(1,5);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Putting it to the test
&lt;/h2&gt;

&lt;p&gt;There are 6 tests that I need to pass:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;sums numbers within the range (1 ms)&lt;/li&gt;
&lt;li&gt;Works with large numbers&lt;/li&gt;
&lt;li&gt;Works with larger number first (1 ms)&lt;/li&gt;
&lt;li&gt;Returns ERROR with negative numbers&lt;/li&gt;
&lt;li&gt;Returns ERROR with non-number parameters&lt;/li&gt;
&lt;li&gt;Returns ERROR with non-number parameters (1 ms)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's tackle these, starting from all the tests that should return &lt;code&gt;ERROR&lt;/code&gt;. The first two tests have already passed based on our code above. To pass the rest of the tests, we need to use &lt;code&gt;if...else&lt;/code&gt; statements in our &lt;code&gt;sumAll&lt;/code&gt; function&lt;/p&gt;

&lt;h3&gt;
  
  
  Returns ERROR with negative numbers
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (startNum &amp;lt; 0 || endNum &amp;lt; 0) {
        return 'ERROR';
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Returns ERROR with non-number parameters
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (startNum &amp;lt; 0 || endNum &amp;lt; 0 || typeof(startNum) !== 'number' || typeof(endNum) !== 'number') {
        return 'ERROR';
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Works with larger number first (1 ms)
&lt;/h3&gt;

&lt;p&gt;Working with larger number first means &lt;code&gt;startNum&lt;/code&gt; &amp;gt; &lt;code&gt;endNum&lt;/code&gt;.  For this, we need to reverse the loop that we had above. Instead of incrementing, we will decrement&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (startNum &amp;lt; 0 || endNum &amp;lt; 0 || typeof(startNum) !== 'number' || typeof(endNum) !== 'number') {
        return 'ERROR';
    } else if (startNum &amp;gt; endNum) {
        for (let i = startNum; i &amp;gt;= endNum; i--) {
            sum += i;
        }
        return sum
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;&lt;em&gt;Finally, we add in the incremental for loop we had above&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sumAll = function(startNum, endNum) {
    let sum = 0;
    if (startNum &amp;lt; 0 || endNum &amp;lt; 0 || typeof(startNum) !== 'number' || typeof(endNum) !== 'number') {
        return 'ERROR';
    } else if (startNum &amp;lt; endNum) {
        for (let i = startNum; i &amp;lt;= endNum; i++) {
            sum += i;
        }
        return sum;
    } else if (startNum &amp;gt; endNum) {
        for (let i = startNum; i &amp;gt;= endNum; i--) {
            sum += i;
        }
        return sum
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✓ sums numbers within the range (1 ms)&lt;br&gt;
✓ works with large numbers&lt;br&gt;
✓ works with larger number first&lt;br&gt;
✓ returns ERROR with negative numbers&lt;br&gt;
✓ returns ERROR with non-number parameters&lt;br&gt;
✓ returns ERROR with non-number parameters&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;All test have passed! On to the next exercise...&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>Career Pivot into Development Journal, Day 5: JS Practice 3 – reverseString.js</title>
      <dc:creator>TakDevelops</dc:creator>
      <pubDate>Wed, 23 Mar 2022 13:10:21 +0000</pubDate>
      <link>https://dev.to/takdevelops/career-pivot-into-development-journal-day-4-js-practice-3-reversestringjs-4d48</link>
      <guid>https://dev.to/takdevelops/career-pivot-into-development-journal-day-4-js-practice-3-reversestringjs-4d48</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;On to the next exercise&lt;/em&gt;&lt;/strong&gt;...&lt;/p&gt;




&lt;h2&gt;
  
  
  Understanding the problem
&lt;/h2&gt;

&lt;p&gt;Create a function that takes a user’s string input and reverses the string. For example. &lt;code&gt;reverseString(’hello there’)&lt;/code&gt; returns 'ereht olleh’&lt;/p&gt;




&lt;h2&gt;
  
  
  Plan
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Does program have a UI? What will it look like? What functionality will the interface have? Sketch this out on paper. &lt;strong&gt;&lt;em&gt;The program does not have a UI. It’ll run in the console.&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;What are the inputs? Will the user enter data or will you get input from somewhere else? &lt;strong&gt;&lt;em&gt;The user will input a string when prompted&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;What’s the desired output? &lt;strong&gt;&lt;em&gt;The reverse of the string that the user inputed&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Pseudocode
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Declare a function `reverseString` that takes the parameter `string`

Create a loop that splices out each character of the string, starting from the last character

Concatenate each character at every loop and store this in a variable called `stringReversed`

Return `stringReversed`

prompt the user to enter a string and store it in a variable called `string`

Call the function `reverseString(string)`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Divide and Conquer
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Declare a function &lt;code&gt;reverseString&lt;/code&gt; that takes the parameter &lt;code&gt;string&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const reverseString = function(string) {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create a loop that splices out each character of the string, starting from the last character
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (i = string.length - 1; i &amp;gt;= 0; i--) {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We set the first loop to begin at the last character of the string. &lt;code&gt;string.length&lt;/code&gt; gives the number of characters in a string, but the actual index of the last character is &lt;code&gt;string.length&lt;/code&gt;. We run the loop until the last character which is at index 0.&lt;/p&gt;

&lt;h3&gt;
  
  
  Concatenate each character at every loop and store this in a variable called &lt;code&gt;stringReversed&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let stringReversed = '';

stringReversed += string[i];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Return &lt;code&gt;stringReversed&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return stringReversed;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Prompt the user to enter a string and store it in a variable called &lt;code&gt;string&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = prompt('Enter a word or short sentence below');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Call the function &lt;code&gt;reverseString(string)&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;reverseString(string);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Putting it all together
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const reverseString = function(string) {
    let stringReversed = '';
    for (let i = string.length -1; i &amp;gt;= 0; i--) {
        stringReversed += string[i];
    }
    return stringReversed;
};

string = prompt('Enter any word or short sentence below');
reverseString (string);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>devjournal</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Career Pivot into Development Journal, Day 4: JS Practice 2 – repeatString.js</title>
      <dc:creator>TakDevelops</dc:creator>
      <pubDate>Tue, 22 Mar 2022 02:16:29 +0000</pubDate>
      <link>https://dev.to/takdevelops/career-pivot-into-development-journal-day-4-js-practice-2-repeatstringjs-1ako</link>
      <guid>https://dev.to/takdevelops/career-pivot-into-development-journal-day-4-js-practice-2-repeatstringjs-1ako</guid>
      <description>&lt;p&gt;&lt;strong&gt;_Just finished Fundamentals 4 of The Odin Project...now onto the practice section. _&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/TakDevelops/javascript-exercises/tree/main/02_repeatString"&gt;repeatString assignment link&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Understanding the Problem
&lt;/h2&gt;

&lt;p&gt;Write a function that repeats a string a given number of times, both parameters inputted by the user. In other words, the string will be repeated, or concatenated, next to each other &lt;code&gt;num&lt;/code&gt; number of times&lt;/p&gt;




&lt;h2&gt;
  
  
  Plan
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Does program have a UI? What will it look like? What functionality will the interface have? Sketch this out on paper. &lt;strong&gt;&lt;em&gt;No UI&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;What are the inputs? Will the user enter data or will you get input from somewhere else?
&lt;strong&gt;&lt;em&gt;- string = any string that a user inputs when prompted&lt;/em&gt;&lt;/strong&gt;
&lt;strong&gt;&lt;em&gt;- num = any number the user inputs when prompted&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;What’s the desired output? &lt;strong&gt;&lt;em&gt;A string that concatenates itself n number of times&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Pseudocode
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prompt the user to input a string and store this value in the variable `string`

Prompt the user to input a number and store this value in the variable `num`

Concatenate the `string` `num` number of times by looping `num` number of times, and save it to a variable

return the concatenated string
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Divide and Conquer
&lt;/h2&gt;

&lt;p&gt;Let's start with the most straight forward subproblems first...&lt;/p&gt;

&lt;h3&gt;
  
  
  Prompt the user to input a string and store this value in the variable &lt;code&gt;string&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = prompt('Enter a string');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Prompt the user to input a number and store this value in the variable &lt;code&gt;num&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;num = prompt('Enter a number');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Now let's figure out the more complex algorithm&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Concatenate the &lt;code&gt;string&lt;/code&gt; &lt;code&gt;num&lt;/code&gt; number of times by looping &lt;code&gt;num&lt;/code&gt; number of times, and save it to a variable
&lt;/h3&gt;

&lt;p&gt;Let's create a loop first&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = 0; i &amp;lt; num; i++) {

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll declare a variable to store the concatenated string, then concatenate this with the user's input &lt;code&gt;string&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = 0; i &amp;lt; num; i++) {
    let concatenatedString = '';
    concatenatedString += string;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value of &lt;code&gt;concatenatedString&lt;/code&gt; should initially be empty because on the first loop, we want &lt;code&gt;concatenatedString&lt;/code&gt; to only return one &lt;code&gt;string&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  return the concatenated string
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = 0; i &amp;lt; num; i++) {
    let concatenatedString = '';
    concatenatedString += string;
}
    return concatenatedString;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We want the final value of concatenatedString to be returned at the end of the loop.&lt;/p&gt;




&lt;h2&gt;
  
  
  Putting it all together
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const repeatString = function(string, num) {
    let concatenatedString = '';
    for (i = 0; i &amp;lt; num; i++) {
        concatenatedString += string;
    }
    return concatenatedString;
};

string = prompt('Enter one word below');
num = prompt('Enter a number below');

repeatString(string, num);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Explaining the algorithm in plain english
&lt;/h2&gt;

&lt;p&gt;We declared a function repeatString initially that takes the parameters string and num.&lt;/p&gt;

&lt;p&gt;Inside this function, we declare a variable called concatenatedString. It's initial value is set as an empty string&lt;/p&gt;

&lt;p&gt;Then a loop loops num number of times and concatenates concatenatedString to string. In the first loop since concatenatedString is initially empty, an empty string '' is concatenated with the string input&lt;/p&gt;

&lt;p&gt;So let's assume the string parameter = hey&lt;/p&gt;

&lt;p&gt;In the first loop, concatenatedString = '' + hey which = hey.&lt;/p&gt;

&lt;p&gt;In the second loop, the expression concatenatedString += string equals concatenatedString = hey + hey&lt;/p&gt;

&lt;p&gt;Etc etc. When the loop ends the final value of concatenatedString is returned&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>Career Pivot into Development Journal, Day 3: Arrays &amp; Array Methods</title>
      <dc:creator>TakDevelops</dc:creator>
      <pubDate>Wed, 16 Mar 2022 13:43:08 +0000</pubDate>
      <link>https://dev.to/takdevelops/career-pivot-into-development-journal-day-3-arrays-array-methods-5h2f</link>
      <guid>https://dev.to/takdevelops/career-pivot-into-development-journal-day-3-arrays-array-methods-5h2f</guid>
      <description>&lt;p&gt;&lt;strong&gt;Key Points:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Damn, array methods are pretty powerful!&lt;/li&gt;
&lt;li&gt;An array is a special type of variable, an ordered collection of items (strings, numbers, or other things)&lt;/li&gt;
&lt;li&gt;Array indexes start with 0. [0] is the first element. [1] is the second element.&lt;/li&gt;
&lt;li&gt;Arrays allow us to deal with a large quantity of strings and numbers.&lt;/li&gt;
&lt;li&gt;Array methods allow us to manipulate arrays.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Arrays
&lt;/h2&gt;

&lt;p&gt;This is how we declare an array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const cars = ['Saab', 'Volvo', 'BMW'];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Arrays are also unaffected by spaces and line breaks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const cars = [
  'Saab',
  'Volvo',
  'BMW'
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Change an Array Element
&lt;/h3&gt;

&lt;p&gt;We can target a specific element by its index and change it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const cars = ['Saab','Volvo', 'BMW'];
cars [0] = 'Toyota';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Accessing the First Array Element
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ['Banana', 'Orange', 'Apple', 'Mango'];
fruits[0];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Accessing the Last Array Element
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ['Banana', 'Orange', 'Apple', 'Mango'];
fruits[fruits.length - 1];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;fruits.length&lt;/code&gt; gives us the number of elements in the array. In the case, there are 4 elements. However, the 4th index in this array is non-existent since the indexes are from 0-3. Therefore, we must subtract 1 to access the last array element.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding Array Elements
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ['Banana', 'Orange', 'Apple', 'Mango'];
fruits.push('Kiwi');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Difference Between Arrays and Objects
&lt;/h3&gt;

&lt;p&gt;Arrays are a type of object. However, the difference is that array items are indexed with numbers, whereas objects are indexed with names.&lt;/p&gt;




&lt;h2&gt;
  
  
  Array Methods
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;toString()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Converts an array to a string of (comma separated) array values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ['Banana', 'Orange', 'Apple', 'Mango'];
fruits.toString() // Banana,Orange,Apple,Mango;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;join()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Behaves like &lt;code&gt;toString()&lt;/code&gt; but we can specify a separator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ['Banana', 'Orange', 'Apple', 'Mango'];
fruits.join(', '); // 'Banana', 'Orange', 'Apple', 'Mango'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;pop()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Popping in Javascript means taking out elements. Think of it like "popping" out elements from an array. This method "pops" out the last element:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ['Banana', 'Orange', 'Apple', 'Mango'];
fruits.pop(); // 'Mango'
fruits; // ['Banana', 'Orange', 'Apple']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;push()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Pushing in Javascript means adding element. Think of it like "pushing" in a new element into an existing array. This method pushes a new element to the end of the array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ['Banana', 'Orange', 'Apple', 'Mango'];
fruits.push('Kiwi'); // 5
fruits; // ['Banana', 'Orange', 'Apple', 'Mango', 'Kiwi']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;shift()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Similar to popping, but works on the first element instead of the last:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ['Banana', 'Orange', 'Apple', 'Mango'];
fruits.shift(); // 'Banana'
fruits; // ['Orange', 'Apple', 'Mango']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;unshift()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Similar to pushing, but adds elements to the beginning instead of end of array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ['Banana', 'Orange', 'Apple', 'Mango'];
fruits.unshift('Lemon'); // 5
fruits; // ['Lemon', 'Banana', 'Orange', 'Apple', 'Mango']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;concat()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Allows us to combine (concatenate) multiple arrays together:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr1 = ['Apple', 'Microsoft', 'Amazon'];
const arr2 = ['Netflix', 'Google', 'Facebook'];

arr1.concat(arr2); // ['Apple', 'Microsoft', 'Amazon', 'Netflix', 'Google', 'Facebook']

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can combine as many arrays as we want:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr1 = ['Apple', 'Microsoft', 'Amazon'];
const arr2 = ['Netflix', 'Google', 'Facebook'];
const arr3 = ['Tesla', 'Samsung', 'Huawei'];

arr1.concat(arr2, arr3); // ['Apple', 'Microsoft', 'Amazon', 'Netflix', 'Google', 'Facebook', 'Tesla', 'Samsung', 'Huawei']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;splice()&lt;/code&gt;
&lt;/h3&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>Career Pivot into Development Journal, Day 2.1: Rock, Paper Scissors (cont.)</title>
      <dc:creator>TakDevelops</dc:creator>
      <pubDate>Tue, 15 Mar 2022 09:46:41 +0000</pubDate>
      <link>https://dev.to/takdevelops/career-pivot-into-development-journal-day-21-rock-paper-scissors-cont-5gfc</link>
      <guid>https://dev.to/takdevelops/career-pivot-into-development-journal-day-21-rock-paper-scissors-cont-5gfc</guid>
      <description>&lt;h2&gt;
  
  
  Next, let's tackle this subproblem:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;If the user wins, alert the string ‘You Win!’
and add 1 point to the user
then return the current score of the user and the computer

If the computer wins, alert the string ‘Boohoo, you lost to the computer.’
and add 1 point to the user
then return the current score of the user and the computer

If the user and computer draw, alert the string ‘It’s a draw’
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This subproblem can be broken down into further subproblems to simplify out task. Let's first solve &lt;code&gt;If the user wins, alert the string ‘You Win!’&lt;/code&gt;, &lt;code&gt;If the computer wins, alert the string ‘Boohoo, you lost to the computer.’&lt;/code&gt;, &lt;code&gt;If the user and computer draw, alert the string ‘It’s a draw’&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Write a function that will play a single round of Rock Paper Scissors taking two parameters, playerSelection and computerSelection, and return a winner or loser.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let playRound = function (playerSelection, computerSelection) {
    if (playerSelection === computerSelection) {
        alert ('It\'s a draw!');
    } else if (playerSelection === 'rock' &amp;amp;&amp;amp; computerSelection === 'paper') {
        alert ('Sorry, you lose! Paper beats rock.');
    } else if (playerSelection === 'rock' &amp;amp;&amp;amp; computerSelection === 'scissors') {
        alert ('You win! Scissors beats rock.')
    } else if (playerSelection === 'paper' &amp;amp;&amp;amp; computerSelection === 'rock') {
        alert ('You win! Paper beats rock.');
    } else if (playerSelection === 'paper' &amp;amp;&amp;amp; computerSelection === 'scissors') {
        alert ('Sorry, you lose! Scissors beats paper');
    } else if (playerSelection === 'scissors' &amp;amp;&amp;amp; computerSelection === 'paper') {
        alert ('You win! Scissors beats paper');
    } else if (playerSelection === 'scissors' &amp;amp;&amp;amp; computerSelection === 'rock') {
        alert ('Sorry, you lose! Rock beats scissors');
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we can move on to solving adding 1 point to the user when the user wins, and adding 1 point to the computer when the computer wins.&lt;/p&gt;

&lt;p&gt;First, we must declare two variables that stores the respective scores:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let playerScore = 0;
let computerScore = 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can then use &lt;code&gt;+= 1&lt;/code&gt; to add 1 point to what &lt;code&gt;playerScore&lt;/code&gt; or &lt;code&gt;computerScore&lt;/code&gt; was previously equal to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let playRound = function (playerSelection, computerSelection) {
    if (playerSelection === computerSelection) {
        alert ('It\'s a draw!');
    } else if (playerSelection === 'rock' &amp;amp;&amp;amp; computerSelection === 'paper') {
        computerScore += 1;
        alert ('Sorry, you lose! Paper beats rock.');
    } else if (playerSelection === 'rock' &amp;amp;&amp;amp; computerSelection === 'scissors') {
        playerScore += 1;
        alert ('You win! Scissors beats rock.')
    } else if (playerSelection === 'paper' &amp;amp;&amp;amp; computerSelection === 'rock') {
        playerScore += 1;
        alert ('You win! Paper beats rock.');
    } else if (playerSelection === 'paper' &amp;amp;&amp;amp; computerSelection === 'scissors') {
        computerScore += 1;
        alert ('Sorry, you lose! Scissors beats paper');
    } else if (playerSelection === 'scissors' &amp;amp;&amp;amp; computerSelection === 'paper') {
        playerScore += 1;
        alert ('You win! Scissors beats paper');
    } else if (playerSelection === 'scissors' &amp;amp;&amp;amp; computerSelection === 'rock') {
        computerScore += 1;
        alert ('Sorry, you lose! Rock beats scissors');
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, return the playerScore and computerScore after 1 round:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let playRound = function (playerSelection, computerSelection) {
    if (playerSelection === computerSelection) {
        alert ('It\'s a draw!');
        return (`There is no change in score. Your score = ${playerScore}. Computer's score = ${computerScore}`);
    } else if (playerSelection === 'rock' &amp;amp;&amp;amp; computerSelection === 'paper') {
        computerScore += 1;
        alert ('Sorry, you lose! Paper beats rock.');
        return (`Your score = ${playerScore}. Computer's score = ${computerScore}`);
    } else if (playerSelection === 'rock' &amp;amp;&amp;amp; computerSelection === 'scissors') {
        playerScore += 1;
        alert ('You win! Scissors beats rock.')
        return (`Your score = ${playerScore}. Computer's score = ${computerScore}`);
    } else if (playerSelection === 'paper' &amp;amp;&amp;amp; computerSelection === 'rock') {
        playerScore += 1;
        alert ('You win! Paper beats rock.');
        return (`Your score = ${playerScore}. Computer's score = ${computerScore}`);
    } else if (playerSelection === 'paper' &amp;amp;&amp;amp; computerSelection === 'scissors') {
        computerScore += 1;
        alert ('Sorry, you lose! Scissors beats paper');
        return (`Your score = ${playerScore}. Computer's score = ${computerScore}`);
    } else if (playerSelection === 'scissors' &amp;amp;&amp;amp; computerSelection === 'paper') {
        playerScore += 1;
        alert ('You win! Scissors beats paper');
        return (`Your score = ${playerScore}. Computer's score = ${computerScore}`);
    } else if (playerSelection === 'scissors' &amp;amp;&amp;amp; computerSelection === 'rock') {
        computerScore += 1;
        alert ('Sorry, you lose! Rock beats scissors');
        return (`Your score = ${playerScore}. Computer's score = ${computerScore}`);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Next, we'll tackle &lt;code&gt;Loop for 5 rounds&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This was provided by The Odin Project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = 0; i &amp;lt; 5; i++) {
   // your code here!
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add in all the above code except for &lt;code&gt;let playerScore = 0;&lt;/code&gt; and &lt;code&gt;let computerScore = 0;&lt;/code&gt;. For the sake of keeping this post short, please view the solution on my &lt;a href="https://takexplores.github.io/rock-paper-scissors/"&gt;GitHub repo&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lastly, we'll announce the winner of the entire game by comparing the user and computer's final scores:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; (playerScore &amp;gt; computerScore) ? alert (`Congratulations, you beat the computer! Your score = ${playerScore}. Computer's score = ${computerScore}` ) : alert (`Boohoooooo, you lost to the computer. Your score = ${playerScore}. Computer's score = ${computerScore}. Refresh and try to win again!`);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;and...we're done with my first ever Javascript project!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Phew, that was a little challenging but very rewarding. This is the beginning of many... &lt;/p&gt;

&lt;p&gt;&lt;a href="https://takdevelops.github.io/rock-paper-scissors/"&gt;Live preview&lt;/a&gt; (make sure to open up console first before navigating to this link)&lt;br&gt;
&lt;a href="https://github.com/TakDevelops/rock-paper-scissors"&gt;Code&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Career Pivot into Development Journal, Day 2: Rock, Paper Scissors</title>
      <dc:creator>TakDevelops</dc:creator>
      <pubDate>Tue, 15 Mar 2022 06:13:58 +0000</pubDate>
      <link>https://dev.to/takdevelops/career-pivot-into-development-journal-day-2-rock-paper-scissors-25dh</link>
      <guid>https://dev.to/takdevelops/career-pivot-into-development-journal-day-2-rock-paper-scissors-25dh</guid>
      <description>&lt;h2&gt;
  
  
  Understanding The Problem
&lt;/h2&gt;

&lt;p&gt;Create a program that takes a user’s input of either Rock, Paper, or Scissors, and play this again a computer that randomly generates Rock, Paper, or Scissors. If the player wins 1 round, add 1 point to the player. If the computer wins 1 round, add 1 point to the player. Play 5 rounds and announce the winner with the most points after 5 rounds&lt;/p&gt;

&lt;h2&gt;
  
  
  Plan
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Does program have a UI? What will it look like? What functionality will the interface have? Sketch this out on paper. &lt;strong&gt;&lt;em&gt;No UI as this will be played in the console&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;What are the inputs? Will the user enter data or will you get input from somewhere else? &lt;strong&gt;&lt;em&gt;User enters in ‘Rock’, ‘Paper’, or ‘Scissors’ when prompted&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;What’s the desired output? &lt;strong&gt;&lt;em&gt;A string announcing the winner of the round&lt;/em&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;em&gt;A point added to the winner&lt;/em&gt;&lt;/strong&gt;. &lt;strong&gt;&lt;em&gt;A final string announcement of the winner at the end of 5 rounds&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Given input X, what are the steps necessary to return output Y?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Pseudocode
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;When the user inputs a string of ‘rock’, ‘paper’, or ‘scissors’

Call the computer’s random selection of ‘rock’, ‘paper’, or ‘scissors’

Compare the user’s input with the computer’s random selection

If the user wins, alert the string ‘You Win!’
and add 1 point to the user
then return the current score of the user and the computer

If the computer wins, alert the string ‘Boohoo, you lost to the computer.’
and add 1 point to the user
then return the current score of the user and the computer

If the user and computer draw, alert the string ‘It’s a draw’

Loop for 5 rounds

If the user’s final score is greater than the computer’s final score
alert ‘Congratulations, you beat the computer!

If the computer’s final score is greater than the user’s final score
alert ‘Sorry, you lost to the computer...’
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Divde &amp;amp; Conquer
&lt;/h2&gt;

&lt;p&gt;Now, let's pick the simplest subproblem from the pseudocode above to solve. &lt;/p&gt;

&lt;h3&gt;
  
  
  Let's start with &lt;code&gt;Call the computer’s random selection of ‘rock’, ‘paper’, or ‘scissors’&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;In order to do this, we first have to create a variable with an array of strings that can be selected upon:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const options = ['rock', 'paper', 'scissors'];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, we can use Math.random to generate a random number between 0 and &amp;lt;1, then multiply by options.length (which equals 3):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Math.random() * options.length
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives a number between 0 and 3. However in the &lt;code&gt;options&lt;/code&gt; array, we can only index 0, 1, and 2 for 'rock', 'paper', scissors' respectively. So we can use Math.floor to round down to the nearest integer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Math.floor(Math.random() * options.length)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To select a random item from the array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;options[Math.floor(Math.random() * options.length)];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, declare a function and return the entire expression above in the function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let computerPlay = function () {
    return options[Math.floor(Math.random() * options.length)];
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Next, let's tackle the subproblem &lt;code&gt;When the user inputs a string of ‘rock’, ‘paper’, or ‘scissors’&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;We want to display a prompt, and ensure that it's case-insensitive (so users can input rock, ROCK, RocK or any other variation).&lt;/p&gt;

&lt;p&gt;First, declare a variable that stores the prompt input value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let playerSelection = prompt ('Rock, Paper, or Scissors?');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To ensure it's case insensitive, make all characters in the string that passes through prompt into playerSelection lower case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let playerPlay = playerSelection.toLowerCase();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then set playerSelection = playerPlay:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;playerSelection = playerPlay;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;To be continued...&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
