<?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: Cliff Mirschel</title>
    <description>The latest articles on DEV Community by Cliff Mirschel (@blueboi904).</description>
    <link>https://dev.to/blueboi904</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%2F323585%2Fb48dbb07-f358-4007-b274-b54a888749d7.jpeg</url>
      <title>DEV Community: Cliff Mirschel</title>
      <link>https://dev.to/blueboi904</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/blueboi904"/>
    <language>en</language>
    <item>
      <title>30 Days of Code - Day 1 - Random Quote Generator</title>
      <dc:creator>Cliff Mirschel</dc:creator>
      <pubDate>Tue, 16 Aug 2022 08:28:00 +0000</pubDate>
      <link>https://dev.to/blueboi904/30-days-of-code-day-1-random-quote-generator-5hej</link>
      <guid>https://dev.to/blueboi904/30-days-of-code-day-1-random-quote-generator-5hej</guid>
      <description>&lt;p&gt;Hi, my name is Cliff. I'm a senior software engineer with over 4 years of professional development experience building cutting-edge web/mobile applications. &lt;/p&gt;

&lt;p&gt;I'm starting a new coding challenge for 30 days. I plan on developing a small app each day using a wide range of technologies including JavaScript, Python, HTML, CSS and hopefully many more. &lt;/p&gt;

&lt;p&gt;In making this post I hope that others can see my journey and  potentially learn something or comment if they have any improvements!! I'll be documenting the entire process here on dev.to, so I hope you all will follow along with me,&lt;/p&gt;

&lt;p&gt;So, lets jump right into the app!&lt;/p&gt;

&lt;p&gt;Firstly, I'll start the challenge by creating a random quote web app. My plan with this project is to keep things simple and only use vanilla JavaScript, HTML, and CSS. &lt;/p&gt;

&lt;p&gt;Here's a couple of requirements that I would like from this app:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The background and main color theme of the app will change to another random color on page refresh.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the center of the page, the user should see a component with a quote, author, and links to share the quote via twitter/tumbler.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The component must contain a button to get a new quote if the user presses it.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So jumping right in, I'm going to first focus on setting a random background/theme color for the app.&lt;/p&gt;

&lt;p&gt;I've created a JavaScript filed name &lt;code&gt;script.js&lt;/code&gt;, which I will use to write the scripts to generate a random color.&lt;/p&gt;

&lt;p&gt;We can generate a random color a few lines of code. Right now to keep it simple, we will choose a random color between 3 different colors stored in a list.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3nSUqkto--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jx8cxjg8zx9u2fchs1x5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3nSUqkto--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jx8cxjg8zx9u2fchs1x5.png" alt="Image description" width="592" height="75"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, create a function that will use the document object to change the background and theme color to the random color selected.&lt;/p&gt;

&lt;p&gt;script.js:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u929fL69--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c517owepl7xd0z59cjl3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u929fL69--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c517owepl7xd0z59cjl3.png" alt="Image description" width="715" height="249"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will be our script.js file. Now we can create a basic html and css markup.&lt;/p&gt;

&lt;p&gt;index.html&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;

    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;title&amp;gt;Random Quote&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;div id="wrapper"&amp;gt;
        &amp;lt;div class="box"&amp;gt;
            &amp;lt;div id="content" class="box_content"&amp;gt;
                Hello
            &amp;lt;/div&amp;gt;

        &amp;lt;/div&amp;gt;
        &amp;lt;div class="footer"&amp;gt;by &amp;lt;a href="https://github.com/BlueBoi904"&amp;gt;BlueBoi904&amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;link rel="stylesheet" href="styles.css"&amp;gt;
&amp;lt;script src="script.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;styles.css:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.box {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: antiquewhite;
}
.box_content {

}

body {
    background-color: #333;
    color: #333;
    font-family:sans-serif;
    font-weight: 400;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now whenever we visit the page, the page and text will be a random color.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2M3yg1ip--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bvann03hxebzhpj3jtrh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2M3yg1ip--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bvann03hxebzhpj3jtrh.png" alt="Image description" width="757" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UU5tP7if--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cqz67x7xyg17e75fsct6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UU5tP7if--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cqz67x7xyg17e75fsct6.png" alt="Image description" width="713" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So now that we have requirement #1 satisfied, lets move on to the second!&lt;/p&gt;

&lt;p&gt;Javascript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const projectName = 'random-quote-machine';
let quotesData;

var colors = [
  '#16a085',
  '#27ae60',
  '#2c3e50',
  '#f39c12',
  '#e74c3c',
  '#9b59b6',
  '#FB6964',
  '#342224',
  '#472E32',
  '#BDBB99',
  '#77B1A9',
  '#73A857'
];
var currentQuote = '',
  currentAuthor = '';

function getQuotes() {
  return $.ajax({
    headers: {
      Accept: 'application/json'
    },
    url:
      'https://gist.githubusercontent.com/camperbot/5a022b72e96c4c9585c32bf6a75f62d9/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json',
    success: function (jsonQuotes) {
      if (typeof jsonQuotes === 'string') {
        quotesData = JSON.parse(jsonQuotes);
        console.log('quotesData');
        console.log(quotesData);
      }
    }
  });
}

function getRandomQuote() {
  return quotesData.quotes[
    Math.floor(Math.random() * quotesData.quotes.length)
  ];
}

function getQuote() {
  let randomQuote = getRandomQuote();

  currentQuote = randomQuote.quote;
  currentAuthor = randomQuote.author;

  $('#tweet-quote').attr(
    'href',
    'https://twitter.com/intent/tweet?hashtags=quotes&amp;amp;related=freecodecamp&amp;amp;text=' +
      encodeURIComponent('"' + currentQuote + '" ' + currentAuthor)
  );

  $('#tumblr-quote').attr(
    'href',
    'https://www.tumblr.com/widgets/share/tool?posttype=quote&amp;amp;tags=quotes,freecodecamp&amp;amp;caption=' +
      encodeURIComponent(currentAuthor) +
      '&amp;amp;content=' +
      encodeURIComponent(currentQuote) +
      '&amp;amp;canonicalUrl=https%3A%2F%2Fwww.tumblr.com%2Fbuttons&amp;amp;shareSource=tumblr_share_button'
  );

  $('.quote-text').animate({ opacity: 0 }, 500, function () {
    $(this).animate({ opacity: 1 }, 500);
    $('#text').text(randomQuote.quote);
  });

  $('.quote-author').animate({ opacity: 0 }, 500, function () {
    $(this).animate({ opacity: 1 }, 500);
    $('#author').html(randomQuote.author);
  });

  var color = Math.floor(Math.random() * colors.length);
  $('html body').animate(
    {
      backgroundColor: colors[color],
      color: colors[color]
    },
    1000
  );
  $('.button').animate(
    {
      backgroundColor: colors[color]
    },
    1000
  );
}

$(document).ready(function () {
  getQuotes().then(() =&amp;gt; {
    getQuote();
  });

  $('#new-quote').on('click', getQuote);
});

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

&lt;/div&gt;



&lt;p&gt;HTML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;link
  rel="stylesheet"
  href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"
/&amp;gt;
&amp;lt;div id="wrapper"&amp;gt;
  &amp;lt;div id="quote-box"&amp;gt;
    &amp;lt;div class="quote-text"&amp;gt;
      &amp;lt;i class="fa fa-quote-left"&amp;gt; &amp;lt;/i&amp;gt;&amp;lt;span id="text"&amp;gt;&amp;lt;/span&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="quote-author"&amp;gt;- &amp;lt;span id="author"&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="buttons"&amp;gt;
      &amp;lt;a
        class="button"
        id="tweet-quote"
        title="Tweet this quote!"
        target="_top"
      &amp;gt;
        &amp;lt;i class="fa fa-twitter"&amp;gt;&amp;lt;/i&amp;gt;
      &amp;lt;/a&amp;gt;
      &amp;lt;a
        class="button"
        id="tumblr-quote"
        title="Post this quote on tumblr!"
        target="_blank"
      &amp;gt;
        &amp;lt;i class="fa fa-tumblr"&amp;gt;&amp;lt;/i&amp;gt;
      &amp;lt;/a&amp;gt;
      &amp;lt;button class="button" id="new-quote"&amp;gt;New quote&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div class="footer"&amp;gt;by &amp;lt;a href="https://codepen.io/BlueBoi904/"&amp;gt;BlueBoi904&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js"&amp;gt;&amp;lt;/script&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;SCSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import url('https://fonts.googleapis.com/css?family=Raleway:400,500');
* {
  margin: 0;
  padding: 0;
  list-style: none;
  vertical-align: baseline;
}

div {
  position: relative;
  z-index: 2;
}

body {
  background-color: #333;
  color: #333;
  font-family: 'Raleway', sans-serif;
  font-weight: 400;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
.footer {
  width: 450px;
  text-align: center;
  display: block;
  margin: 15px auto 30px auto;
  font-size: 0.8em;
  color: #fff;
  a {
    font-weight: 500;
    text-decoration: none;
    color: #fff;
  }
}
#quote-box {
  border-radius: 3px;
  position: relative;
  //margin:8% auto auto auto;
  width: 450px;
  padding: 40px 50px;
  display: table;
  background-color: #fff;
  .quote-text {
    i {
      font-size: 1em;
      margin-right: 0.4em;
    }
    text-align: center;
    width: 450px;
    height: auto;
    clear: both;
    font-weight: 500;
    font-size: 1.75em;
  }
  .quote-author {
    width: 450px;
    height: auto;
    clear: both;
    padding-top: 20px;
    font-size: 1em;
    text-align: right;
  }
  .buttons {
    width: 450px;
    margin: auto;
    display: block;
    .button {
      height: 38px;
      border: none;
      border-radius: 3px;
      color: #fff;
      background-color: #333;
      outline: none;
      font-size: 0.85em;
      padding: 8px 18px 6px 18px;
      margin-top: 30px;
      opacity: 1;
      cursor: pointer;
      &amp;amp;:hover {
        opacity: 0.9;
      }
      &amp;amp;#tweet-quote,
      &amp;amp;#tumblr-quote {
        float: left;
        padding: 0px;
        padding-top: 8px;
        text-align: center;
        font-size: 1.2em;
        margin-right: 5px;
        height: 30px;
        width: 40px;
      }
      &amp;amp;#new-quote {
        float: right;
      }
    }
  }
}

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

&lt;/div&gt;



&lt;p&gt;Thanks for reading along, please check in for the next progress update!&lt;/p&gt;

&lt;p&gt;Cliff&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>news</category>
    </item>
  </channel>
</rss>
