<?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: Hamza Elkotb</title>
    <description>The latest articles on DEV Community by Hamza Elkotb (@hamzadev).</description>
    <link>https://dev.to/hamzadev</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%2F742624%2F174fca85-1eeb-4087-8527-968aa76a7220.png</url>
      <title>DEV Community: Hamza Elkotb</title>
      <link>https://dev.to/hamzadev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hamzadev"/>
    <language>en</language>
    <item>
      <title>Open source JavaScript Quiz App</title>
      <dc:creator>Hamza Elkotb</dc:creator>
      <pubDate>Tue, 25 Jul 2023 20:51:30 +0000</pubDate>
      <link>https://dev.to/hamzadev/open-source-javascript-quiz-app-42fn</link>
      <guid>https://dev.to/hamzadev/open-source-javascript-quiz-app-42fn</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6tdbaiy6zenvwcl0zeol.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6tdbaiy6zenvwcl0zeol.png" alt="Quiz Appp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Last days I was applying on JS by making some JS tutorials. I started building a simple Quiz App using vanilla js. I decided to make it &lt;code&gt;open-source&lt;/code&gt; so any js developer can contribute to it on github or learn new things from it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;p&gt;The project contains the following features:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Beautiful UI&lt;/li&gt;
&lt;li&gt;Responsive UI&lt;/li&gt;
&lt;li&gt;Quiz page&lt;/li&gt;
&lt;li&gt;Results Page&lt;/li&gt;
&lt;li&gt;Basic quiz app features:

&lt;ul&gt;
&lt;li&gt;next\previous btns&lt;/li&gt;
&lt;li&gt;move between questions&lt;/li&gt;
&lt;li&gt;choose answer&lt;/li&gt;
&lt;li&gt;timer &lt;/li&gt;
&lt;li&gt;submit btn&lt;/li&gt;
&lt;li&gt;question points &lt;/li&gt;
&lt;li&gt;number of questions&lt;/li&gt;
&lt;li&gt;see results&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Logic
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Quiz content is rendered from &lt;code&gt;JSON&lt;/code&gt; file  - to &lt;code&gt;HTML&lt;/code&gt; page -  that will contain every thing (time, questions, options, true answers ...etc) using &lt;code&gt;API&lt;/code&gt; fetch. "&lt;em&gt;Simulating calling quiz data from server&lt;/em&gt;"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The answers will be putted in a new &lt;code&gt;JSON&lt;/code&gt; file  - Copy of the Quiz &lt;code&gt;JSON&lt;/code&gt; file - that will be sent to another &lt;code&gt;html&lt;/code&gt; page  - called results.html -  where the answers file will be rendered in it with the same quiz data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Answers &lt;code&gt;JSON&lt;/code&gt; will be sent to the results Page using &lt;code&gt;postMessage&lt;/code&gt; and message &lt;code&gt;EventListener&lt;/code&gt;. then rendered.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; the only different between Quiz &lt;code&gt;JSON&lt;/code&gt; and Answers &lt;code&gt;JSON&lt;/code&gt;, is that the answers &lt;code&gt;JSON&lt;/code&gt; will includes the user answers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Last Note:&lt;/strong&gt; This project is completely built on &lt;code&gt;FP&lt;/code&gt; (Functional Programming) Concept. I'll continue developing it from time to time and improve the code and make it cleaner.&lt;/p&gt;

&lt;h3&gt;
  
  
  Finally
&lt;/h3&gt;

&lt;p&gt;This project is completely &lt;code&gt;open-source&lt;/code&gt;, under &lt;code&gt;MIT license&lt;/code&gt;. You can contribute on it and learn from each others.&lt;/p&gt;

&lt;p&gt;👉 Source Code: &lt;a href="https://github.com/HamzaElkotp/Quiz-Answers_Project" rel="noopener noreferrer"&gt;https://github.com/HamzaElkotp/Quiz-Answers_Project&lt;/a&gt;&lt;br&gt;
🌐 Live Preview: &lt;a href="https://quizanswersproject.netlify.app/quiz.html" rel="noopener noreferrer"&gt;https://quizanswersproject.netlify.app/quiz.html&lt;/a&gt;&lt;br&gt;
🐱 My GitHub: &lt;a href="https://github.com/HamzaElkotp" rel="noopener noreferrer"&gt;https://github.com/HamzaElkotp&lt;/a&gt;&lt;br&gt;
👕 To get Coding Shirts: &lt;a href="https://my-store-c54a10.creator-spring.com/" rel="noopener noreferrer"&gt;https://my-store-c54a10.creator-spring.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Understanding Generators in JavaScript with examples</title>
      <dc:creator>Hamza Elkotb</dc:creator>
      <pubDate>Sun, 09 Oct 2022 18:21:36 +0000</pubDate>
      <link>https://dev.to/hamzadev/understanding-generators-in-javascript-with-examples-2p6o</link>
      <guid>https://dev.to/hamzadev/understanding-generators-in-javascript-with-examples-2p6o</guid>
      <description>&lt;h1&gt;
  
  
  First of all: what is Generators in js?🤔
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Generators are functions.&lt;/li&gt;
&lt;li&gt;Generator Function Run Its Code When Required.&lt;/li&gt;
&lt;li&gt;Generators Are iterables.&lt;/li&gt;
&lt;li&gt;It doesn't run unless you need it.&lt;/li&gt;
&lt;li&gt;Generator Function Return Special Object [Generator Object].&lt;/li&gt;
&lt;li&gt;That Object can loop on generator function data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;❗NOTE&lt;/strong&gt;: The data is present but when the function run, it generates the data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Briefly:
&lt;/h3&gt;

&lt;p&gt;Generators functions are different from normal function it doesn't run until you need it, they are iterable &amp;amp; return special object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdyhld3zux9kl39p2d3mc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdyhld3zux9kl39p2d3mc.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Example from real live:
&lt;/h3&gt;

&lt;p&gt;like tickets generator device, when you pay it generates new serial number and print on new ticket then you get it, Here serial number already exists but it didn't print until get order to create a new ticket.&lt;/p&gt;

&lt;h3&gt;
  
  
  Generators Methods:
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;next()&lt;/code&gt; to get next yield.&lt;br&gt;
&lt;code&gt;return()&lt;/code&gt; to return a value &amp;amp; stop generating.&lt;br&gt;
&lt;code&gt;throw()&lt;/code&gt; to throw an error &amp;amp; stop generating.&lt;/p&gt;
&lt;h3&gt;
  
  
  Generators properties:
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;done&lt;/code&gt; if iteration done or not, return boolean value.&lt;br&gt;
&lt;code&gt;value&lt;/code&gt; current yield value.&lt;/p&gt;
&lt;h3&gt;
  
  
  Syntax:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;generatorName&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now you can put in it any JS code and also can add the data that want to generate and we'll see how in next paragraph👇.&lt;/p&gt;
&lt;h1&gt;
  
  
  Yield Data | Data Production Process
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;Yield&lt;/code&gt; keyword used to data production process, and then you can loop on it using &lt;code&gt;next()&lt;/code&gt; with Generator Object.&lt;/p&gt;

&lt;p&gt;so you use &lt;code&gt;yield&lt;/code&gt; keyword and put it's value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;generatorName&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bye&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can put any type of data (&lt;em&gt;boolean, object...&lt;/em&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  lets try Looping on Generator function Yields🔃
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nf"&gt;generateNums&lt;/span&gt;&lt;span class="p"&gt;()){&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the output will be:&lt;br&gt;
    &lt;code&gt;"hello"&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;"bye"&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;1&lt;/code&gt;&lt;br&gt;
    &lt;code&gt;2&lt;/code&gt;&lt;br&gt;
this also what &lt;code&gt;next()&lt;/code&gt; method does!&lt;/p&gt;
&lt;h1&gt;
  
  
  Create Generator Object🏭
&lt;/h1&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;generator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;generatorName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;lets see something will make this clear to you💯&lt;br&gt;
lets check &lt;code&gt;typeof&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;generator&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// object&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;generatorName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// function&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;generator&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Object: Generator {...}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  next method | Accessing Yields
&lt;/h1&gt;

&lt;p&gt;It returns value &amp;amp; done state&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;generator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: "hello", done: false }&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;generator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: "bye", done: false }&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;generator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: 1, done: false }&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;generator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: 2, done: false }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you note every time you use &lt;code&gt;next()&lt;/code&gt; method, it returns the next yield and can't undo this action.⏩&lt;/p&gt;

&lt;p&gt;Now we looped on all yields, if we use &lt;code&gt;next()&lt;/code&gt; again guess what we'll happen!🤔&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;generator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: undefined, done: true }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;yes, it returned &lt;code&gt;value: undefined&lt;/code&gt; that's because there is no more &lt;code&gt;yield&lt;/code&gt; to access, also you'll find &lt;code&gt;done: true&lt;/code&gt; because loop is over.&lt;/p&gt;

&lt;h3&gt;
  
  
  value property:
&lt;/h3&gt;

&lt;p&gt;Use it with &lt;code&gt;next()&lt;/code&gt; method to get the current yield value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;generator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I want you to think why it returned undefined.🤔&lt;br&gt;
I'll be 😊 if you answered it true in comments.&lt;/p&gt;
&lt;h3&gt;
  
  
  done property:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;generator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;done&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h1&gt;
  
  
  return &amp;amp; throw Methods | Controlling yield process
&lt;/h1&gt;
&lt;h3&gt;
  
  
  1- return
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;return&lt;/code&gt; method to stop yielding process, making &lt;code&gt;done:true&lt;/code&gt; &amp;amp; &lt;code&gt;value: undefined&lt;/code&gt; also you can return a custom value.&lt;br&gt;
Let's see an example😬&lt;/p&gt;

&lt;p&gt;these are our generator function &amp;amp; generator object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;gen2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;also we can access normally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: "A, done: false }&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: "B", done: false }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if we used &lt;code&gt;return&lt;/code&gt; method this is what will happen&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: undefined, done: true }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you noticed we still have one &lt;code&gt;yield&lt;/code&gt; we didn't access it before, plus if you used &lt;code&gt;next()&lt;/code&gt; method again you'll get &lt;code&gt;{ value: undefined, done: true }&lt;/code&gt;.&lt;br&gt;
that is what &lt;code&gt;return&lt;/code&gt; is here to do!&lt;/p&gt;

&lt;p&gt;also you can return any value, by putting it between ()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;visit youtube.com/devcoder&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now output will change to &lt;code&gt;{ value: "visit youtube.com/devcoder", done: true }&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  2- throw
&lt;/h3&gt;

&lt;p&gt;It's like &lt;code&gt;return()&lt;/code&gt; method, but it throws custom errors like &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw" rel="noopener noreferrer"&gt;&lt;code&gt;throw&lt;/code&gt;&lt;/a&gt; keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;gen3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: "A, done: false }&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;throw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi coder!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Error: Uncaught Hi coder!&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// not working&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;❗NOTE&lt;/strong&gt;: &lt;code&gt;throw()&lt;/code&gt; method doesn't stop your code, just stop the generator object.&lt;/p&gt;

&lt;p&gt;Use Case: for example we have a generator function to generate random numbers, if that number is duplicated, it throws error.&lt;/p&gt;

&lt;h1&gt;
  
  
  Loop on generator yields
&lt;/h1&gt;

&lt;p&gt;if we tried to loop through &lt;code&gt;gen2&lt;/code&gt; no output will appear&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;gen2&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;that's because we already accessed &lt;code&gt;gen2&lt;/code&gt; in past examples, so will create new generator object and loop though&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;gen4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;gen4&lt;/span&gt; &lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;try that, will work.✅&lt;/p&gt;

&lt;h1&gt;
  
  
  Generate Infinite Numbers
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;infinity&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;inf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;infinity&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now as you see we're able to add normal JS code inside generator function,&lt;br&gt;
1- when &lt;code&gt;inf&lt;/code&gt; visit &lt;code&gt;infinity()&lt;/code&gt; for first time &lt;code&gt;index = 0&lt;/code&gt; and will enter the infinite loop and will not exit&lt;br&gt;
2- in loop, every time we use &lt;code&gt;next()&lt;/code&gt;, index will increment and yield will equal the new index value.&lt;/p&gt;

&lt;p&gt;NOW, let's use &lt;code&gt;next()&lt;/code&gt; on it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: 0, done: false }&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: 1, done: false }&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: 2, done: false }&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: 3, done: false }&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  🔴&lt;strong&gt;IMPORTANT&lt;/strong&gt;
&lt;/h1&gt;

&lt;h1&gt;
  
  
  yield*
&lt;/h1&gt;

&lt;p&gt;What is deference between &lt;code&gt;yield&lt;/code&gt; &amp;amp; &lt;code&gt;yield*&lt;/code&gt;, the answer will be clear if we try it with an array.👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nc"&gt;GeneAll&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;gen754&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;GeneAll&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's try to access for one time&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen754&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: 4, done: false }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as you noticed it returned only the first element from our array.&lt;br&gt;
let's try again!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen754&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: 5, done: false }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it returned the second element.&lt;br&gt;
let's try again!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen754&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: [6,7], done: false }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But now it returned the full array, why???🤯&lt;/p&gt;

&lt;p&gt;the &lt;code&gt;yield*&lt;/code&gt; treat value as individual elements, so it converts the array value into more small values, but &lt;code&gt;yield&lt;/code&gt; doesn't do this.&lt;br&gt;
The same thing applies to &lt;code&gt;string&lt;/code&gt;! &lt;/p&gt;
&lt;h1&gt;
  
  
  Delegate Generator Function | (Generator Function Chaining)
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;it's a function that delegate another function yield&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;take an example🎴&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nc"&gt;AllYields&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// without starter"*" will return the name of function&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// this will include an array contains all nums() yields&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// without starter"*" it'll return an array&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;gen55&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AllYields&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see what will happen in first &lt;code&gt;next()&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen55&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: Generator, done: false }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as you saw it returned the function name&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen55&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: 1, done: false }&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen55&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: 2, done: false }&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;gen55&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Object { value: 3, done: false }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What happened behind the since?🤯&lt;/strong&gt;&lt;br&gt;
1- &lt;code&gt;gen55&lt;/code&gt; will go to every &lt;code&gt;yield&lt;/code&gt; and enter it to access all data in it.&lt;br&gt;
2- it will find that first &lt;code&gt;yield&lt;/code&gt; without * and contains a generator function &lt;code&gt;nums()&lt;/code&gt;.&lt;br&gt;
3- will return it's name.&lt;br&gt;
4- after that &lt;code&gt;gen55&lt;/code&gt; will go to next &lt;code&gt;yield&lt;/code&gt; &lt;em&gt;"yield* nums()"&lt;/em&gt; with * so, will go through it.&lt;br&gt;
5- it will find that it contains other yields so, will go through every &lt;code&gt;yield&lt;/code&gt; and return it on every &lt;code&gt;next()&lt;/code&gt; method call until it end accessing all &lt;code&gt;nums()&lt;/code&gt; yields.&lt;br&gt;
6- and now it went through out our second &lt;code&gt;yield&lt;/code&gt; &lt;em&gt;"yield* nums()"&lt;/em&gt; .&lt;br&gt;
7- Then go to next &lt;code&gt;yield&lt;/code&gt; in &lt;code&gt;AllYields()&lt;/code&gt; and repeat the same process etc...&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;This was all what I know about &lt;strong&gt;generators in javascript&lt;/strong&gt;, I hope you enjoyed with this article and learned a new thing,&lt;br&gt;
I'll be happy for that.&lt;br&gt;
If you have any notes about this article or new information tell me about in comments.&lt;br&gt;
Follow me on &lt;a href="https://www.youtube.com/Devcoder" rel="noopener noreferrer"&gt;YouTube&lt;/a&gt; , &lt;a href="https://github.com/HamzaElkotp" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; .&lt;br&gt;
&lt;strong&gt;For Coding T-shirts visit: &lt;a href="//my-store-c54a10.preview.teespring.com/"&gt;CodingShirts&lt;/a&gt; .&lt;/strong&gt;&lt;br&gt;
And don't forget to read these references👇.&lt;br&gt;
See you again, Bye👋&lt;/p&gt;

&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator" rel="noopener noreferrer"&gt;MDN: Generator&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*" rel="noopener noreferrer"&gt;MDN: function*&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators" rel="noopener noreferrer"&gt;MDN: Iterators and generators&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.digitalocean.com/community/tutorials/understanding-generators-in-javascript" rel="noopener noreferrer"&gt;digitalocean: understanding generators in JS&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.javatpoint.com/es6-generators" rel="noopener noreferrer"&gt;JavaPoint: ES6 Generators&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>generators</category>
    </item>
    <item>
      <title>Booking List📅Tutorial Using DOM {JavaScript}</title>
      <dc:creator>Hamza Elkotb</dc:creator>
      <pubDate>Fri, 08 Apr 2022 20:54:04 +0000</pubDate>
      <link>https://dev.to/hamzadev/booking-listtutorial-using-dom-javascript-4cj1</link>
      <guid>https://dev.to/hamzadev/booking-listtutorial-using-dom-javascript-4cj1</guid>
      <description>&lt;p&gt;This simple tutorial will be a simple exercise about JavaScript DOM,&lt;br&gt;
I'll use: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;li&gt;CSS =&amp;gt; Bulma or any css framework toin bulma make styling easy&lt;/li&gt;
&lt;li&gt;JS =&amp;gt; DOM&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  What is DOM?
&lt;/h2&gt;

&lt;p&gt;(Document Object Model) is an interface that allows developers to manipulate the content, structure and style of a website.&lt;/p&gt;
&lt;h2&gt;
  
  
  📁Starting Up Project
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;HTML File&lt;/li&gt;
&lt;li&gt;JavaScript File&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;📙HTML&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Main HTML Structure&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;&amp;lt;html dir="ltr" lang="en"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;title&amp;gt;JS BookList App&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body class="container"&amp;gt;

&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&amp;lt;script src="javascript.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;HTML head: &lt;em&gt;adding Bulma CDN&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;&amp;lt;link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;HTML Body: creating form&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create a form and add id to can select it using js DOM easily to get inputs value.&lt;/li&gt;
&lt;li&gt;create 2 inputs: one to get the full name and other to get phone number.&lt;/li&gt;
&lt;li&gt;every input has a name to can select it in js DOM.&lt;/li&gt;
&lt;li&gt;every input above it there is a label.&lt;/li&gt;
&lt;li&gt;after every input there is a paragraph that contains input instructions with &lt;em&gt;.help&lt;/em&gt; class.&lt;/li&gt;
&lt;li&gt;create select to select the destination.&lt;/li&gt;
&lt;li&gt;adding select options with values to can read it in js DOM.&lt;/li&gt;
&lt;li&gt;creating submit button that check if the inputs are filled then get values from them.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;form action="" class="form" id="bookForm"&amp;gt;
    &amp;lt;!-- Name Input --&amp;gt;
    &amp;lt;label class="label"&amp;gt;Full Name&amp;lt;/label&amp;gt;
    &amp;lt;div class="control"&amp;gt;
        &amp;lt;input class="input is-success" type="text" placeholder="Firts name" name="Fname"&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;p class="help is-success"&amp;gt;Enter Your Full Name in Your ID Card&amp;lt;/p&amp;gt;

    &amp;lt;!-- Phone Input --&amp;gt;
    &amp;lt;label class="label"&amp;gt;Phone Number&amp;lt;/label&amp;gt;
    &amp;lt;div class="control"&amp;gt;
        &amp;lt;input class="input is-success" type="text" placeholder="Firts name" name="Pnum"&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;p class="help is-success"&amp;gt;Enter Your Phone Number&amp;lt;/p&amp;gt;

    &amp;lt;!-- Destination Select --&amp;gt;
    &amp;lt;label class="label"&amp;gt;Destination:&amp;lt;/label&amp;gt;
    &amp;lt;div class="control"&amp;gt;
        &amp;lt;div class="select"&amp;gt;
            &amp;lt;select&amp;gt;
                &amp;lt;option value="KSA: Mekka"&amp;gt;KSA: Mekka&amp;lt;/option&amp;gt;
                &amp;lt;option value="KSA: Ryahd"&amp;gt;KSA: Ryahd&amp;lt;/option&amp;gt;
                &amp;lt;option value="Egy: Cairo"&amp;gt;Egy: Cairo&amp;lt;/option&amp;gt;
                &amp;lt;option value="Egy: Sharm Elshek"&amp;gt;Egy: Sharm Elshek&amp;lt;/option&amp;gt;
                &amp;lt;option value="USA: Area 51"&amp;gt;USA: Area 51&amp;lt;/option&amp;gt;
            &amp;lt;/select&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;!-- Form Submit --&amp;gt;
    &amp;lt;button class="button is-success is-fullwidth"&amp;gt;Submit&amp;lt;/button&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;: &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P5vH-yHy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wjsy1hrhdqsinjt5ugay.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P5vH-yHy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wjsy1hrhdqsinjt5ugay.png" alt="form box result" width="800" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML: creating result box&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;will contain a table that contains the submitted data&lt;/li&gt;
&lt;li&gt;contain clear button to remove all table data&lt;/li&gt;
&lt;li&gt;adding "&lt;em&gt;res&lt;/em&gt;" class
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="res"&amp;gt;

&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;HTML {result box}: creating table&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;style using Bulma classes
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;table class="result table is-fullwidth is-bordered is-striped is-narrow is-hoverable is-success"&amp;gt;

&amp;lt;/table&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;HTML {result box}: adding table thead&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;style using Bulma classes&lt;/li&gt;
&lt;li&gt;adding main columns
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;thead class="has-background-success"&amp;gt;
    &amp;lt;tr&amp;gt;
        &amp;lt;th&amp;gt;Full Name&amp;lt;/th&amp;gt;
        &amp;lt;th&amp;gt;Phone Number&amp;lt;/th&amp;gt;
        &amp;lt;th&amp;gt;Destination&amp;lt;/th&amp;gt;
    &amp;lt;/tr&amp;gt;
&amp;lt;/thead&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;HTML {result box}: adding table thead&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;&amp;lt;tbody&amp;gt;
&amp;lt;/tbody&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;let it empty, because content will be added using JS when user clicks form submit button&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML {result box}: creating clear button&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;styling in Bulma
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="control"&amp;gt;
    &amp;lt;button class="button is-danger delB"&amp;gt;clear&amp;lt;/button&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;last thing in html But not least in our project&lt;br&gt;
&lt;strong&gt;HTML {form}: adding warnning text&lt;/strong&gt;&lt;br&gt;
this text will be shown when user clicks submit button and one of the inputs is empty&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;adding before submit button&lt;/li&gt;
&lt;li&gt;style color to red and bigger font-size, in bulma&lt;/li&gt;
&lt;li&gt;adding &lt;em&gt;warning&lt;/em&gt; class to can select this element in js DOM
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p class="help is-danger has-text-centered is-size-6 warning"&amp;gt;Fill Empty Inputs Please!&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Final HTML Result&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--umxg7opj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fvmqp4kcj7vak4qd997s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--umxg7opj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fvmqp4kcj7vak4qd997s.png" alt="Final HTML result" width="800" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final HTML Code&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;&amp;lt;html dir="ltr" lang="en"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;title&amp;gt;JS BookList App&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css"&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body class="container"&amp;gt;
    &amp;lt;form action="" class="form" id="bookForm"&amp;gt;
        &amp;lt;div class="field"&amp;gt;
            &amp;lt;label class="label"&amp;gt;Full Name&amp;lt;/label&amp;gt;
            &amp;lt;div class="control"&amp;gt;
              &amp;lt;input class="input is-success" type="text" placeholder="Firts name" name="Fname"&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;p class="help is-success"&amp;gt;Enter Your Full Name in Your ID Card&amp;lt;/p&amp;gt;

            &amp;lt;label class="label"&amp;gt;Phone Number&amp;lt;/label&amp;gt;
            &amp;lt;div class="control"&amp;gt;
              &amp;lt;input class="input is-success" type="text" placeholder="Firts name" name="Pnum"&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;p class="help is-success"&amp;gt;Enter Your Phone Number&amp;lt;/p&amp;gt;

            &amp;lt;label class="label"&amp;gt;Destination:&amp;lt;/label&amp;gt;
            &amp;lt;div class="control"&amp;gt;
                &amp;lt;div class="select"&amp;gt;
                    &amp;lt;select&amp;gt;
                      &amp;lt;option value="KSA: Mekka"&amp;gt;KSA: Mekka&amp;lt;/option&amp;gt;
                      &amp;lt;option value="KSA: Ryahd"&amp;gt;KSA: Ryahd&amp;lt;/option&amp;gt;
                      &amp;lt;option value="Egy: Cairo"&amp;gt;Egy: Cairo&amp;lt;/option&amp;gt;
                      &amp;lt;option value="Egy: Sharm Elshek"&amp;gt;Egy: Sharm Elshek&amp;lt;/option&amp;gt;
                      &amp;lt;option value="USA: Area 51"&amp;gt;USA: Area 51&amp;lt;/option&amp;gt;
                    &amp;lt;/select&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;p class="help is-danger has-text-centered is-size-6 warning"&amp;gt;Fill Empty Inputs Please!&amp;lt;/p&amp;gt;
            &amp;lt;button class="button is-success is-fullwidth"&amp;gt;Submit&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/form&amp;gt;

    &amp;lt;br&amp;gt;

    &amp;lt;div class="res"&amp;gt;
        &amp;lt;table class="result table is-fullwidth is-bordered is-striped is-narrow is-hoverable is-success"&amp;gt;

            &amp;lt;thead class="has-background-success"&amp;gt;
                &amp;lt;tr&amp;gt;
                    &amp;lt;th&amp;gt;Full Name&amp;lt;/th&amp;gt;
                    &amp;lt;th&amp;gt;Phone Number&amp;lt;/th&amp;gt;
                    &amp;lt;th&amp;gt;Destination&amp;lt;/th&amp;gt;
                &amp;lt;/tr&amp;gt;
            &amp;lt;/thead&amp;gt;

            &amp;lt;tbody&amp;gt;
            &amp;lt;/tbody&amp;gt;

        &amp;lt;/table&amp;gt;
        &amp;lt;div class="control"&amp;gt;
            &amp;lt;button class="button is-danger delB"&amp;gt;clear&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/html&amp;gt;
&amp;lt;script src="javascript.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;📒JavaScript&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;JS: styling Body&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;document.querySelector("body").style.cssText = "padding: 40px 20px";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;JS: styling Elements with "&lt;em&gt;help&lt;/em&gt;" class&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;get all "&lt;em&gt;.help&lt;/em&gt;" elements in the array&lt;/li&gt;
&lt;li&gt;loop on them and add to them style
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let helparr = document.querySelectorAll(".help");
helparr.forEach(ele =&amp;gt; {
    ele.style.cssText = "margin-bottom: 15px";
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;JS: styling "&lt;em&gt;warning&lt;/em&gt;" element&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;hide this element using opacity
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let warn = document.querySelector(".warning");
warn.style.cssText = "opacity: 0";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;JS: styling resultBox ("&lt;em&gt;res&lt;/em&gt;") element&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;make scroll
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let resultBox = document.querySelector(".res");
resultBox.style.cssText = "height: 400px; overflow: auto;";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;JS: styling clear button box("&lt;em&gt;control&lt;/em&gt;") element&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;make button fixed above when scrolling
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let control = resultBox.querySelector(".control");
control.style.cssText = "position: sticky; bottom: 0;";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;JS {form}: select using js&lt;/strong&gt;&lt;br&gt;
we need this step to get the inputs value and control submit conditions&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let form = document.getElementById("bookForm");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;JS {form}: select elements&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;here we can access the inputs and control it or get them values
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let FnameV = form.Fname;
let PnumV = form.Pnum;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;JS {form}: select submit button&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;let SubmitButton = form.querySelector("button");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;JS {table}: select tbody&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;we select it now to can make form submit conditions
clearly: when submit form adds the data to the table
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let SubmitButton = form.querySelector("button");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;JS {form}: make submit logic&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;start with onclick
when click the button do the next
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SubmitButton.onclick = function(ele){

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;JS {submit}: disable the main function of button&lt;/strong&gt;&lt;br&gt;
when click the submit button, it automatically refresh the page, but this isn't what we need, we need when submit the form the the data automatically enter the table&lt;br&gt;
so we well use preventDefault()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ele.preventDefault();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: _ele _here == this button onclick function (what this button will do when click on it)&lt;br&gt;
To see a clearer picture, type:&lt;br&gt;
&lt;code&gt;console.log(ele)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JS {submit}: adding conditions (if)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;check on inputs if they are empty or not&lt;/li&gt;
&lt;li&gt;if not empty:

&lt;ul&gt;
&lt;li&gt;hide warning text when it's shown.&lt;/li&gt;
&lt;li&gt;create a new variable, call: "FnameValue" and it equal the Fname value.&lt;/li&gt;
&lt;li&gt;create a new variable, call: "PnumValue" and it equal the Pnum value.&lt;/li&gt;
&lt;li&gt;create a new variable, call: "DisValue" and it equal the select value.&lt;/li&gt;
&lt;li&gt;inner all these variables into the table
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(FnameV.value != "" &amp;amp;&amp;amp; PnumV.value != ""){
    warn.style.opacity = "0";
    let FnameValue = form.Fname.value;
    let PnumValue = form.Pnum.value;
    let DisValue = form.querySelector("select").value;

    tbody.innerHTML += (`&amp;lt;tr&amp;gt; &amp;lt;th&amp;gt;${FnameValue}&amp;lt;/th&amp;gt; &amp;lt;th&amp;gt;${PnumValue}&amp;lt;/th&amp;gt; &amp;lt;th&amp;gt;${DisValue}&amp;lt;/th&amp;gt; &amp;lt;/tr&amp;gt;`);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;JS {submit}: adding conditions (else)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if the inputs empty:

&lt;ul&gt;
&lt;li&gt;show warning text
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;else{
    warn.style.opacity = "1";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;JS {Clear Button}: functionality&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;when click the button the table be empty
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let delbutton = document.querySelector(".delB");
delbutton.onclick = function(){
    tbody.innerHTML = "";
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Final JavaScript Code&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;// ################### Normalize ################### 
document.querySelector("body").style.cssText = "padding: 40px 20px";
let helparr = document.querySelectorAll(".help");
helparr.forEach(ele =&amp;gt; {
    ele.style.cssText = "margin-bottom: 15px";
})

let warn = document.querySelector(".warning");
warn.style.cssText = "opacity: 0";

// ################# result BOX ################ 
let resultBox = document.querySelector(".res");
resultBox.style.cssText = "height: 400px; overflow: auto;";
let control = resultBox.querySelector(".control");
control.style.cssText = "position: sticky; bottom: 0;";

// ################### Form ################### 
let form = document.getElementById("bookForm");
let FnameV = form.Fname;
let PnumV = form.Pnum;
let SubmitButton = form.querySelector("button");
let tbody = document.querySelector("tbody");

SubmitButton.onclick = function(ele){
    ele.preventDefault();
    if(FnameV.value != "" &amp;amp;&amp;amp; PnumV.value != ""){
        warn.style.opacity = "0";
        let FnameValue = form.Fname.value;
        let PnumValue = form.Pnum.value;
        let DisValue = form.querySelector("select").value;

        tbody.innerHTML += (`&amp;lt;tr&amp;gt; &amp;lt;th&amp;gt;${FnameValue}&amp;lt;/th&amp;gt; &amp;lt;th&amp;gt;${PnumValue}&amp;lt;/th&amp;gt; &amp;lt;th&amp;gt;${DisValue}&amp;lt;/th&amp;gt; &amp;lt;/tr&amp;gt;`);
    }
    else{
        warn.style.opacity = "1";
    }
};

// ################### Clear Button ################### 
let delbutton = document.querySelector(".delB");
delbutton.onclick = function(){
    tbody.innerHTML = "";
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;strong&gt;That's&lt;/strong&gt; the end of this tutorial I hope you like it
&lt;/h1&gt;

&lt;p&gt;If you like Coding Shirts Check my merch😊&lt;br&gt;
&lt;a href="https://my-store-c54a10.preview.teespring.com/"&gt;My Merch&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See You in next article👋&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>dom</category>
      <category>tutorial</category>
      <category>hackwithdg</category>
    </item>
  </channel>
</rss>
