<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>august_breeze</title>
        <link>https://velog.io/</link>
        <description></description>
        <lastBuildDate>Sat, 10 Jun 2023 18:42:06 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>august_breeze</title>
            <url>https://velog.velcdn.com/images/jisu_lee/profile/0e65cd5c-5855-4e52-8764-30168257df03/image.jpg</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. august_breeze. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/jisu_lee" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[Javascript Certification]]></title>
            <link>https://velog.io/@jisu_lee/Javascript-Certification</link>
            <guid>https://velog.io/@jisu_lee/Javascript-Certification</guid>
            <pubDate>Sat, 10 Jun 2023 18:42:06 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/jisu_lee/post/2ad1cfa3-6fd3-4c67-a705-4f39cf215541/image.png" alt="">
노마드코더 - 바닐라 JS 초급 단계 수강을 완료했습니다!</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[ReactJS Day7]]></title>
            <link>https://velog.io/@jisu_lee/ReactJS-Day7</link>
            <guid>https://velog.io/@jisu_lee/ReactJS-Day7</guid>
            <pubDate>Sat, 10 Jun 2023 17:29:50 GMT</pubDate>
            <description><![CDATA[<p>오늘은 ReactJS 스터디 일곱 번째 날입니다..새벽 2시반..일찍일찍 강의를 들읍시다..
<img src="https://velog.velcdn.com/images/jisu_lee/post/196906b4-24e6-40db-b83e-a8305ffff93d/image.png" alt=""></p>
<h4 id="7071-to-do-list">#7.0~7.1 (To do List)</h4>
<p>creating a list of to-dos in the console</p>
<pre><code class="language-javascript">import { useState, useEffect } from &quot;react&quot;;

function App(){
  const [toDo, setToDo] = useState(&quot;&quot;);
  const [toDos, setToDos] = useState([]);
  const onChange =(event) =&gt; setToDo(event.target.value);
  const onSubmit = (event) =&gt; {
    event.preventDefault();
    //if toDo is empty, will kill the function
    //else add toDo and empty the input (will call setToDo again and empty the input as settoDo modifies the toDo value)
    if(toDo===&quot;&quot;){
      return;
    }
    //we don&#39;t modify the state directly, we always use the modifier function
    setToDo(&quot;&quot;);
    //we make a function and we receive the current array, then we want to return a new array, the new array will have the toDo + all the previous toDos
    // we do [something you want to add, ...the previous array]
    //will receive the empty arrary [] for the very first time so it will be just toDo, ...[]
    setToDos(currentArray =&gt;[toDo, ...currentArray]);
  };
  console.log(toDos);
  //need to add {} inside &lt;h1&gt;&lt;/h1&gt; for javascript or javascript will understand it only as a string
  return &lt;div&gt;
    &lt;h1&gt;My To Dos ({toDos.length})&lt;/h1&gt;
    &lt;form onSubmit={onSubmit}&gt;
    &lt;input onChange={onChange} value={toDo} type=&quot;text&quot; placeholder=&quot;Write your to-do&quot;/&gt;
    &lt;button&gt;Add To Do&lt;/button&gt;
    &lt;/form&gt;
  &lt;/div&gt;;
  //button inside the form will submit the form so we will prevent default 
}

export default App;</code></pre>
<p>using map function to display the list</p>
<pre><code class="language-javascript">import { useState, useEffect } from &quot;react&quot;;

function App(){
  const [toDo, setToDo] = useState(&quot;&quot;);
  const [toDos, setToDos] = useState([]);
  const onChange =(event) =&gt; setToDo(event.target.value);
  const onSubmit = (event) =&gt; {
    event.preventDefault();
    if(toDo===&quot;&quot;){
      return;
    }
    //(1) if setToDo is called with an empty string, then toDo will be an empty string
    setToDo(&quot;&quot;);
    //(2) we send a function instead of value
    //will receive the empty arrary [] for the very first time so it will be just toDo, ...[]
    setToDos(currentArray =&gt;[toDo, ...currentArray]);
  };
  return &lt;div&gt;
    &lt;h1&gt;My To Dos ({toDos.length})&lt;/h1&gt;
    &lt;form onSubmit={onSubmit}&gt;
    &lt;input onChange={onChange} value={toDo} type=&quot;text&quot; placeholder=&quot;Write your to-do&quot;/&gt;
    &lt;button&gt;Add To Do&lt;/button&gt;
    &lt;/form&gt;
    &lt;hr /&gt;
    &lt;ul&gt;
    {toDos.map((item, index)=&gt;&lt;li key={index}&gt;{item}&lt;/li&gt;)}
    &lt;/ul&gt;
  &lt;/div&gt;;
  //function in map() will be run for every item in the array and return a new array (wiil transform and put in the new array) 
  //first argument of the map function is the value (item) and the second argument is the index, key should be unique 
}

export default App;</code></pre>
<h4 id="72-coin-tracker">#7.2 (Coin Tracker)</h4>
<p>extracting json from response and setting the value with the json (coins)</p>
<pre><code class="language-javascript">import { useState, useEffect } from &quot;react&quot;;

function App(){
  const [loading, setLoading] = useState(true);
  //default values which is empty but not undefined
  const [coins, setCoins] = useState([])
  //will be watching nothing so the code will only run once
  //extract the json from the response of tickers, so we fetch and then get the response and want to return response.json and want to take that json
  //when we get the json which is the coins, we will setCoins to the value of the json  (will have array of coins)
  useEffect(()=&gt;{
    fetch(&quot;https://api.coinpaprika.com/v1/tickers&quot;).then((respone)=&gt;
    respone.json()
    ).then(json =&gt; setCoins(json));
    setLoading(false);
  },[])
  return(
    &lt;div&gt;
    &lt;h1&gt;The Coins! ({coins.length})&lt;/h1&gt;
    {loading ? &lt;strong&gt;Loading...&lt;/strong&gt; : null}
    &lt;ul&gt;
      {coins.map((coin)=&gt; &lt;li&gt;{coin.name} ({coin.symbol}): ${coin.quotes.USD.price} USD&lt;/li&gt;)}
    &lt;/ul&gt;
  &lt;/div&gt;
  //we don&#39;t need the index for the coin as the coin has the id which we can use as the key
  );
}
export default App;</code></pre>
<p>using select and option instead of ul and li</p>
<pre><code class="language-javascript">import { useState, useEffect } from &quot;react&quot;;

function App(){
  const [loading, setLoading] = useState(true);
  //default values which is empty but not undefined
  const [coins, setCoins] = useState([])
  //will be watching nothing so the code will only run once
  //extract the json from the response of tickers, so we fetch and then get the response and want to return response.json and want to take that json
  //when we get the json which is the coins, we will setCoins to the value of the json  (will have array of coins)
  useEffect(()=&gt;{
    fetch(&quot;https://api.coinpaprika.com/v1/tickers&quot;).then((respone)=&gt;
    respone.json()
    ).then(json =&gt; setCoins(json));
    setLoading(false);
  },[])
  return(
    &lt;div&gt;
    &lt;h1&gt;The Coins! {loading ? &quot;&quot; :`(${coins.length})`}&lt;/h1&gt;
    {loading ? &lt;strong&gt;Loading...&lt;/strong&gt; : (&lt;select&gt;
      {coins.map((coin)=&gt; &lt;option&gt;{coin.name} ({coin.symbol}): ${coin.quotes.USD.price} USD&lt;/option&gt;)}
    &lt;/select&gt;)}
  &lt;/div&gt;
  //we don&#39;t need the index for the coin as the coin has the id which we can use as the key
  );
}
export default App;</code></pre>
<p>the challenge (converting how many coins you can get from investing dollars)</p>
<pre><code class="language-javascript">import { useState, useEffect } from &quot;react&quot;;

function App() {
  const [loading, setLoading] = useState(true);
  const [coins,setCoins] = useState([]); 
  const [cost,setCost] = useState(1);
  const [need, setNeed] = useState(1);
  const onChange = (event) =&gt; {
    setCost(event.target.value);
    setNeed(1);
  }
  const handleInput = (event) =&gt; {
    setNeed(event.target.value);
  } 
  useEffect(()=&gt;{
    fetch(&quot;https://api.coinpaprika.com/v1/tickers&quot;)
      .then((response) =&gt; response.json())
      .then((json) =&gt; {
        setCoins(json);
        setLoading(false);
      });
  },[]);
  return (
  &lt;div&gt;
    &lt;h1&gt;The coins!{loading ? &quot;&quot; :` Here are..${coins.length} coins`}&lt;/h1&gt;
    {loading ? &lt;strong&gt;loading...&lt;/strong&gt; : &lt;select onChange={onChange}&gt;
      &lt;option&gt;Select Coin!&lt;/option&gt;
      {coins.map((coin , index) =&gt;
      &lt;option 
        key={index} 
        value={coin.quotes.USD.price} 
        id={coin.symbol}
        symbol = {coin.symbol} &gt;
        {coin.name}({coin.symbol}) : ${coin.quotes.USD.price} USD
        &lt;/option&gt;
       )}
    &lt;/select&gt;}
    &lt;h2&gt;Please enter the amount (in dollars)&lt;/h2&gt;
    &lt;div&gt;
      &lt;input type=&quot;number&quot; value={need} onChange={handleInput} placeholder=&quot;dollars ($)&quot;/&gt;
    &lt;/div&gt;
    &lt;h2&gt;You can get {need/cost}&lt;/h2&gt;
  &lt;/div&gt;);
}
export default App;</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[ReactJS Day6]]></title>
            <link>https://velog.io/@jisu_lee/wssac8h6</link>
            <guid>https://velog.io/@jisu_lee/wssac8h6</guid>
            <pubDate>Sat, 03 Jun 2023 09:22:09 GMT</pubDate>
            <description><![CDATA[<p>오늘은 ReactJS 스터디 여섯 번째 날입니다. 오늘도 화이탱구리구리!</p>
<h4 id="60-introduction">#6.0 (Introduction)</h4>
<p>when we change the state, the whole code renders again but with the new value
however, there are sometimes you don&#39;t want to call the whole function again (e.g., when you have an API to call and you have to call the API every time it renders) -&gt; you want some codes in the component only runs one time but never again</p>
<pre><code class="language-javascript">import {useState} from &quot;react&quot;;

function App() {
  const [counter, setValue] = useState(0);
  //counter is set to default and onclick it increments from the previous counter +1
  const onClick = () =&gt; setValue((prev) =&gt; prev+1);
  return (
   &lt;div&gt;&lt;h1&gt;{counter}&lt;/h1&gt;
   &lt;button onClick={onClick}&gt;click me&lt;/button&gt;

  &lt;/div&gt;
  );
}

export default App;</code></pre>
<h4 id="61-useeffect">#6.1 (useEffect)</h4>
<p>using useEffect to make sure the code only runs one time</p>
<pre><code class="language-javascript">import {useState, useEffect} from &quot;react&quot;;
//useEffect takes two argument which is the code we want to run only once, and magical argument

function App() {
  const [counter, setValue] = useState(0);
  //counter is set to default and onclick it increments from the previous counter +1
  const onClick = () =&gt; setValue((prev) =&gt; prev+1);
  console.log(&quot;i run all the time&quot;);
  const iRunOnlyOnce = () =&gt; {
    console.log(&quot;i run only once&quot;);
  };
  useEffect(iRunOnlyOnce, []);
  return (
   &lt;div&gt;
    &lt;h1&gt;{counter}&lt;/h1&gt;
   &lt;button onClick={onClick}&gt;click me&lt;/button&gt;

  &lt;/div&gt;
  );
}

export default App;</code></pre>
<p>another way of writing the code</p>
<pre><code class="language-javascript">import {useState, useEffect} from &quot;react&quot;;
//useEffect takes two argument which is the code we want to run only once, and the dependencies (it is what react.js needs to watch, and if they change react.js will run the code)

function App() {
  const [counter, setValue] = useState(0);
  //counter is set to default and onclick it increments from the previous counter +1
  const onClick = () =&gt; setValue((prev) =&gt; prev+1);
  console.log(&quot;i run all the time&quot;);
  useEffect(()=&gt; {
    console.log(&quot;i run only once - call the api&quot;);
  },[]);
  return (
   &lt;div&gt;
    &lt;h1&gt;{counter}&lt;/h1&gt;
   &lt;button onClick={onClick}&gt;click me&lt;/button&gt;

  &lt;/div&gt;
  );
}

export default App;</code></pre>
<h4 id="62-deps">#6.2 (Deps)</h4>
<p>search for the movie that the user wants only when the movie (the specific component) changes</p>
<pre><code class="language-javascript">import { useState, useEffect } from &quot;react&quot;;

function App() {
    const [counter, setValue] = useState(0);
    const [keyword, setKeyword] = useState(&quot;&quot;);
    const onClick = () =&gt; setValue((prev) =&gt; prev +1);
    const onChange = (event) =&gt; setKeyword(event.target.value);
    console.log(&quot;I run all the time&quot;);
    useEffect(() =&gt; {
        console.log(&quot;CALL THE API...&quot;);
    }, []);
    useEffect(() =&gt; {
      if (keyword !== &quot;&quot; &amp;&amp; keyword.length &gt; 5) {
          console.log(&quot;SEARCH FOR&quot;, keyword);
      }  
  }, [keyword]);
    return (
        &lt;div&gt;
            &lt;input 
                value={keyword}
                onChange={onChange}
                type=&quot;text&quot; 
                placeholder=&quot;Search here...&quot; 
            /&gt;
            &lt;h1&gt;{counter}&lt;/h1&gt;
            &lt;button onClick = {onClick}&gt;click me&lt;/button&gt;
        &lt;/div&gt;
    );
};
export default App;</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/1b653ef7-0c10-4314-b2d1-f851feaba648/image.png" alt=""></p>
<p>making the change for only counter and for only keyword</p>
<pre><code class="language-javascript">import { useState, useEffect } from &quot;react&quot;;

function App() {
    const [counter, setValue] = useState(0);
  //keyword is being modified by setKeyword function
    const [keyword, setKeyword] = useState(&quot;&quot;);
    const onClick = () =&gt; setValue((prev) =&gt; prev +1);
    const onChange = (event) =&gt; setKeyword(event.target.value);
  //will run only one time as we are not watching anybody in [] -&gt; the second argument
    useEffect(() =&gt; {
        console.log(&quot;I run only once&quot;);
    }, []);
  //will run when keyword changes (of the second argument)
    useEffect(() =&gt; {
      console.log(&quot;I run when keyword changes&quot;);
  }, [keyword]);
  useEffect(() =&gt; {
    console.log(&quot;I run when counter changes&quot;);
}, [counter]);
  //run when either one of it changes (i.e., keyword or counter)
  useEffect(() =&gt; {
    console.log(&quot;I run when keyword &amp; counter changes&quot;);
}, [keyword, counter]);
    return (
        &lt;div&gt;
            &lt;input 
                value={keyword}
                onChange={onChange}
                type=&quot;text&quot; 
                placeholder=&quot;Search here...&quot; 
            /&gt;
            &lt;h1&gt;{counter}&lt;/h1&gt;
            &lt;button onClick = {onClick}&gt;click me&lt;/button&gt;
        &lt;/div&gt;
    );
};
export default App;</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/546c3d67-0df7-44e6-8897-61a789062ef6/image.png" alt=""></p>
<h4 id="64-cleanup">#6.4 (Cleanup)</h4>
<p>displaying and hiding certain component</p>
<pre><code class="language-javascript">import { useState, useEffect } from &quot;react&quot;;

function Hello (){
  useEffect (() =&gt; {
    //when we show the component this function runs and shows the console.log line
    console.log(&quot;I&#39;m here!&quot;);
  },[]);
  return &lt;h1&gt;Hello&lt;/h1&gt;;
}
function App() {
  const [showing, setShowing] =useState(false);
  //display the opposite of the previous state
  const onClick = () =&gt; setShowing((prev)=&gt;!prev);
  return &lt;div&gt;
    {showing ? &lt;Hello /&gt; : null}
    &lt;button onClick={onClick}&gt;{showing ? &quot;Hide&quot;:&quot;Show&quot;}&lt;/button&gt;
  &lt;/div&gt;;
}
export default App;</code></pre>
<p>know when the component was created and destroyed -&gt; cleanup
cleanup is not used very often -&gt; Code can be run even when a component is destroyed</p>
<pre><code class="language-javascript">import { useState, useEffect } from &quot;react&quot;;

function Hello (){
  useEffect (() =&gt; {
    //allows you to know when the component was created and destroyed
    console.log(&quot;created:)&quot;);
    return () =&gt; console.log(&quot;destroyed :(&quot;);
  },[]);
  return &lt;h1&gt;Hello&lt;/h1&gt;;
}
function App() {
  const [showing, setShowing] =useState(false);
  //display the opposite of the previous state
  const onClick = () =&gt; setShowing((prev)=&gt;!prev);
  return &lt;div&gt;
    {showing ? &lt;Hello /&gt; : null}
    &lt;button onClick={onClick}&gt;{showing ? &quot;Hide&quot;:&quot;Show&quot;}&lt;/button&gt;
  &lt;/div&gt;;
}
export default App;</code></pre>
<p>another example of using cleanup with using functions</p>
<pre><code class="language-javascript">import { useState, useEffect } from &quot;react&quot;;

function Hello() {
  function byeFn() {
      console.log(&quot;bye :(&quot;);
  }
  function hiFn() {
    //run the hiFn and return byeFn when the component is destroyed
      console.log(&quot;created :)&quot;);
      return byeFn;
  }
  useEffect(hiFn, []);
  return &lt;h1&gt;Hello&lt;/h1&gt;;
}

function App() {
  const [showing, setShowing] =useState(false);
  //display the opposite of the previous state
  const onClick = () =&gt; setShowing((prev)=&gt;!prev);
  return &lt;div&gt;
    {showing ? &lt;Hello /&gt; : null}
    &lt;button onClick={onClick}&gt;{showing ? &quot;Hide&quot;:&quot;Show&quot;}&lt;/button&gt;
  &lt;/div&gt;;
}
export default App;</code></pre>
<p>another way of writing the previous code with function inside of useEffect</p>
<pre><code class="language-javascript">import { useState, useEffect } from &quot;react&quot;;

function Hello() {
  useEffect(() =&gt; {
    console.log(&quot;hi :)&quot;);
    return () =&gt; {
        console.log(&quot;bye :(&quot;);
    }
}, []);
  return &lt;h1&gt;Hello&lt;/h1&gt;;
}

function App() {
  const [showing, setShowing] =useState(false);
  //display the opposite of the previous state
  const onClick = () =&gt; setShowing((prev)=&gt;!prev);
  return &lt;div&gt;
    {showing ? &lt;Hello /&gt; : null}
    &lt;button onClick={onClick}&gt;{showing ? &quot;Hide&quot;:&quot;Show&quot;}&lt;/button&gt;
  &lt;/div&gt;;
}
export default App;</code></pre>
<blockquote>
<p>컴포넌트가 destroy될 때도 코드를 실행할 수 있다 -&gt; return으로 함수를 만들어주면 됨
useEffect는 함수를 받고, 이 함수는 dependency가 변화할 때 호출됨
현재는 dependency가 비어있으니 컴포넌트가 처음 생성될 때 함수가 호출된 후 다시
호출 되지 않음
그래서 컴포넌트가 파괴될 때도 함수를 실행하고 싶으면
useEffect 함수가 새로운 함수를 return해야 함
-&gt; 왜냐면 deps가 비어있으면 자동으로 컴포넌트가 파괴될 때 cleanup함수가 실행되는데 그 과정이 리렌더링으로 useEffect함수가 실행되고 클린업하면서 이전에 있던 이펙트인 console.log(“created :) )가 삭제되고 새로운 이펙트 함수인 return함수가 실행되기 때문이다.
리렌더링 -&gt; 이전 이펙트 클린업 -&gt; 이펙트 실행</p>
</blockquote>
]]></description>
        </item>
        <item>
            <title><![CDATA[ReactJS Day5]]></title>
            <link>https://velog.io/@jisu_lee/ReactJS-Day5</link>
            <guid>https://velog.io/@jisu_lee/ReactJS-Day5</guid>
            <pubDate>Thu, 18 May 2023 14:43:01 GMT</pubDate>
            <description><![CDATA[<p>오늘은 노마드코더 ReactJS 스터디 다섯 번째 날입니다! 오늘도 화이탱!
<img src="https://velog.velcdn.com/images/jisu_lee/post/d6a2e4bc-612a-45d6-9872-cd33c0ee3c5d/image.png" alt=""></p>
<h4 id="40-props">#4.0 (Props)</h4>
<p>props is a way of sending data from a parent component to a child component
not a good way - as you are copying and pasting the same thing, better to have the same component and change only the text in the button</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        function SaveBtn(){
            return &lt;button style={{
                backgroundColor: &quot;tomato&quot;,
                color:&quot;white&quot;,
                padding: &quot;10px 20px&quot;,
                border: 0,
                borderRadius: 10,
            }}&gt;Save Changes&lt;/button&gt;
        }
        function ConfirmBtn(){
            return &lt;button style={{
                backgroundColor: &quot;tomato&quot;,
                color:&quot;white&quot;,
                padding: &quot;10px 20px&quot;,
                border: 0,
                borderRadius: 10,
            }}&gt;Confirm&lt;/button&gt;
        }
        function App(){

            return(
                &lt;div&gt;
                    &lt;SaveBtn /&gt;
                    &lt;ConfirmBtn /&gt;
                &lt;/div&gt;
            );
        };
        const root = document.getElementById(&quot;root&quot;);
        ReactDOM.render(&lt;App/&gt;, root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<p>use the same function but configure only the text
rending <Btn banana="Save Changes" /> would mean Btn({banana:&quot;Save Changes&quot;}) </p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        //props is the property given to the button
        //whatever props you send to the Btn component will be put in the first argument of the Btn function
        // == props will go into the object and will be given in the first argument to the component
        function Btn(props){
            return &lt;button style={{
                backgroundColor: &quot;tomato&quot;,
                color:&quot;white&quot;,
                padding: &quot;10px 20px&quot;,
                border: 0,
                borderRadius: 10,
            }}&gt;{props.banana}&lt;/button&gt;
        }

        function App(){

            return(
                //value of the banana will be &quot;save changes&quot; and &quot;continue&quot;
                &lt;div&gt;
                    &lt;Btn banana=&quot;Save Changes&quot; /&gt;
                    &lt;Btn banana=&quot;Continue&quot; /&gt;
                &lt;/div&gt;
            );
        };
        const root = document.getElementById(&quot;root&quot;);
        ReactDOM.render(&lt;App/&gt;, root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<p>don&#39;t use props that much --&gt; following is the same code from above without using props as an argument</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        //props is the property given to the button
        //whatever props you send to the Btn component will be put in the first arguement of the Btn function
        // == props will go into the object and will be given in the first arguement to the component
        function Btn({banana}){
            return &lt;button style={{
                backgroundColor: &quot;tomato&quot;,
                color:&quot;white&quot;,
                padding: &quot;10px 20px&quot;,
                border: 0,
                borderRadius: 10,
            }}&gt;{banana}&lt;/button&gt;
        }

        function App(){

            return(
                //value of the banana will be &quot;save changes&quot; and &quot;continue&quot;
                &lt;div&gt;
                    &lt;Btn banana=&quot;Save Changes&quot; /&gt;
                    &lt;Btn banana=&quot;Continue&quot; /&gt;
                &lt;/div&gt;
            );
        };
        const root = document.getElementById(&quot;root&quot;);
        ReactDOM.render(&lt;App/&gt;, root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<p>we can add more argument in the object</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        //props is the property given to the button
        //whatever props you send to the Btn component will be put in the first arguement of the Btn function
        // == props will go into the object and will be given in the first arguement to the component
        function Btn({banana, big}){
            return &lt;button style={{
                backgroundColor: &quot;tomato&quot;,
                color:&quot;white&quot;,
                padding: &quot;10px 20px&quot;,
                border: 0,
                borderRadius: 10,
                fontSize: big ? 18 : 15,
            }}&gt;{banana}&lt;/button&gt;
        }

        function App(){

            return(
                //value of the banana will be &quot;save changes&quot; and &quot;continue&quot;
                &lt;div&gt;
                    &lt;Btn banana=&quot;Save Changes&quot; big={true} /&gt;
                    &lt;Btn banana=&quot;Continue&quot; /&gt;
                &lt;/div&gt;
            );
        };
        const root = document.getElementById(&quot;root&quot;);
        ReactDOM.render(&lt;App/&gt;, root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<h4 id="41-memo">#4.1 (Memo)</h4>
<p>using React.useState to change the content of the button</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        //props is the property given to the button
        //whatever props you send to the Btn component will be put in the first arguement of the Btn function
        // == props will go into the object and will be given in the first arguement to the component
        function Btn({banana, onClick1}){
            return &lt;button
                onClick={onClick1}
                style={{
                backgroundColor: &quot;tomato&quot;,
                color:&quot;white&quot;,
                padding: &quot;10px 20px&quot;,
                border: 0,
                borderRadius: 10,
            }}&gt;{banana}&lt;/button&gt;
        }

        function App(){
            const [value, setValue] = React.useState(&quot;Save Changes&quot;);
            const changeValue = () =&gt; setValue(&quot;Revert Changes&quot;);
            return(
                //if I put onClick in the function Btn, then it is an eventlistern, the onClick in the custom component Btn/ is not an eventlistener, this is just a prop even though the name might be the same
                &lt;div&gt;
                    &lt;Btn banana={value} onClick1={changeValue}/&gt;
                    &lt;Btn banana=&quot;Continue&quot; /&gt;
                &lt;/div&gt;
            );
        };
        const root = document.getElementById(&quot;root&quot;);
        ReactDOM.render(&lt;App/&gt;, root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<p>we don&#39;t want to re-render if the prop doesn&#39;t change</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        //props is the property given to the button
        //whatever props you send to the Btn component will be put in the first arguement of the Btn function
        // == props will go into the object and will be given in the first arguement to the component
        function Btn({banana, onClick1}){
            console.log(banana,&quot;was rendering&quot;)
            return &lt;button
                onClick={onClick1}
                style={{
                backgroundColor: &quot;tomato&quot;,
                color:&quot;white&quot;,
                padding: &quot;10px 20px&quot;,
                border: 0,
                borderRadius: 10,
            }}&gt;{banana}&lt;/button&gt;
        }
        const MemorizedBtn = React.memo(Btn)
        function App(){
            const [value, setValue] = React.useState(&quot;Save Changes&quot;);
            const changeValue = () =&gt; setValue(&quot;Revert Changes&quot;);
            return(
                //if I put onClick in the function Btn, then it is an eventlistern, the onClick in the custom component Btn/ is not an eventlistener, this is just a prop even though the name might be the same
                &lt;div&gt;
                    &lt;MemorizedBtn banana={value} onClick1={changeValue}/&gt;
                    &lt;MemorizedBtn banana=&quot;Continue&quot; /&gt;
                &lt;/div&gt;
            );
        };
        const root = document.getElementById(&quot;root&quot;);
        ReactDOM.render(&lt;App/&gt;, root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<p>output change from
<img src="https://velog.velcdn.com/images/jisu_lee/post/65b2a7bc-bb31-40ef-b9e5-69d772d1d456/image.png" alt="">
to
<img src="https://velog.velcdn.com/images/jisu_lee/post/809bb22e-039f-4f79-b6c2-117c0c5ccb72/image.png" alt=""></p>
<h4 id="42-prop-types">#4.2 (Prop Types)</h4>
<p>using &#39;propTypes&#39; to define the proptypes</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.development.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/prop-types@15.7.2/prop-types.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;

        function Btn({banana, fontSize}){
            return &lt;button
                style={{
                backgroundColor: &quot;tomato&quot;,
                color:&quot;white&quot;,
                padding: &quot;10px 20px&quot;,
                border: 0,
                borderRadius: 10,
                fontSize,
            }}&gt;{banana}&lt;/button&gt;
        }
        Btn.propTypes = {
            banana: PropTypes.string, 
            fontSize: PropTypes.number,
        }
        function App(){

            return(
                &lt;div&gt;
                    &lt;Btn banana=&quot;Save changes&quot; fontSize={18} /&gt;
                    &lt;Btn banana={14} fontSize={&quot;Continue&quot;} /&gt;
                &lt;/div&gt;
            );
        };
        const root = document.getElementById(&quot;root&quot;);
        ReactDOM.render(&lt;App/&gt;, root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<p>output : we see an error in the console as fontSize for the second Btn is not a number and banana is not a string (UI works find)
<img src="https://velog.velcdn.com/images/jisu_lee/post/7f82a0a4-f09f-4a6e-8dc9-fa114bcdb46f/image.png" alt="">
giving values to the ones that are not defined</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.development.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/prop-types@15.7.2/prop-types.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        //you can give default values if it is not defined (ex. fontSize)
        function Btn({banana, fontSize=5}){
            return &lt;button
                style={{
                backgroundColor: &quot;tomato&quot;,
                color:&quot;white&quot;,
                padding: &quot;10px 20px&quot;,
                border: 0,
                borderRadius: 10,
                fontSize,
            }}&gt;{banana}&lt;/button&gt;
        }
        Btn.propTypes = {
            banana: PropTypes.string.isRequired, 
            fontSize: PropTypes.number.isRequired,
        }
        function App(){

            return(
                &lt;div&gt;
                    &lt;Btn banana=&quot;Save changes&quot; fontSize={18} /&gt;
                    &lt;Btn banana=&quot;Font size is 5&quot; /&gt;
                &lt;/div&gt;
            );
        };
        const root = document.getElementById(&quot;root&quot;);
        ReactDOM.render(&lt;App/&gt;, root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<h4 id="50-create-react-app-introduction">#5.0 (Create React App Introduction)</h4>
<ol>
<li>node js 사용자 버전 설치</li>
<li>윈도우키 + R 누르면 실행창 뜸 
3 .열기 칸에 cmd 라고 입력하고 확인 (혹은 command prompt 열기)</li>
<li>나오는 창에 node -v 입력해서 잘 설치됐는지 확인</li>
<li>vscode 상단 메뉴에서 Terminal - New Terminal 클릭</li>
<li>npm start하면 window에 새로운 창이 자동으로 뜸</li>
<li>자동으로 설치되었던 src 폴더에 모든 파일을 저장할 것 --&gt; 가장 중요한 것은 index.js</li>
</ol>
<h4 id="51-tour-of-cra">#5.1 (Tour of CRA)</h4>
<p>first option of applying button color is making a css file and importing that css file in index.js</p>
<pre><code class="language-javascript">import React from &#39;react&#39;;
import ReactDOM from &#39;react-dom/client&#39;;
import App from &#39;./App&#39;;
import &quot;./styles.css&quot;;

const root = ReactDOM.createRoot(document.getElementById(&#39;root&#39;));
root.render(
  &lt;React.StrictMode&gt;
    &lt;App /&gt;
  &lt;/React.StrictMode&gt;
);</code></pre>
<p>style.css file</p>
<pre><code class="language-css">button {
    color: white;
    background-color: tomato;
}</code></pre>
<p>if we import the css that will be applied to all the buttons in every file
option 2 - we cound manually include the style in javascript code</p>
<pre><code class="language-javascript">import PropTypes from &quot;prop-types&quot;;

function Button({text}) {
    return &lt;button style={{
        backgroundColor:&quot;tomato&quot;,
        color:&quot;white&quot;,
    }}&gt;{text}&lt;/button&gt;; 
}

Button.propTypes= {
    text: PropTypes.string.isRequired,
};

export default Button;</code></pre>
<p>option 3 - the best option is to make a module.css and import styles in the javacript, create a class, and apply the style</p>
<pre><code class="language-javascript">import PropTypes from &quot;prop-types&quot;;
import styles from &quot;./Button.module.css&quot;;

function Button({text}) {
    return &lt;button className={styles.btn}&gt;{text}&lt;/button&gt;; 
}

Button.propTypes= {
    text: PropTypes.string.isRequired,
};

export default Button;</code></pre>
<p>css file would have a class and the css file name will be Button.module.css</p>
<pre><code class="language-css">.btn {
    color: white;
    background-color: tomato;
}</code></pre>
<p>making another css file named App.module.css (the name doesn&#39;t matter however needs to end with .module.css)</p>
<pre><code class="language-css">.title{
    font-family: Impact, Haettenschweiler, &#39;Arial Narrow Bold&#39;, sans-serif;
    font-size: 18px;
}</code></pre>
<p>App.js would contain the classname as styles.whateverclassname</p>
<pre><code class="language-javascript">import Button from &quot;./Button&quot;;
import styles from &quot;./App.module.css&quot;; 

function App() {
  return (
   &lt;div&gt;&lt;h1 className={styles.title}&gt;Welcome back!!!&lt;/h1&gt;
        &lt;Button text={&quot;Continue&quot;} /&gt;

  &lt;/div&gt;
  );
}

export default App;</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/36d0f7d0-ba0a-4194-b4d3-32ee8f1cb83b/image.png" alt=""></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[ReactJS Day4]]></title>
            <link>https://velog.io/@jisu_lee/ReactJS-Day4</link>
            <guid>https://velog.io/@jisu_lee/ReactJS-Day4</guid>
            <pubDate>Sat, 06 May 2023 10:19:54 GMT</pubDate>
            <description><![CDATA[<p>오늘은 노마드코더로 ReactJS를 공부하는 네 번째 날입니다. 오늘도 화이탱입니다!
<img src="https://velog.velcdn.com/images/jisu_lee/post/7be73c84-5a13-423c-abfd-d7962887fabd/image.png" alt=""></p>
<h4 id="35-inputs-and-state">#3.5 (Inputs and State)</h4>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        const root = document.getElementById(&quot;root&quot;);
        function App(){
            //#1 first is the value and the second is the function that we use to modify the value and rerender our component
            const [minutes, setMinutes] = React.useState(0);
            const onChange =(event) =&gt; {
                //#4 function for onChange will be executed and we will get the value to modify to current value
                setMinutes(event.target.value);
            }
            return(
                &lt;div&gt;
                    &lt;h1 className=&quot;hi&quot;&gt;Super Converter&lt;/h1&gt;
                    &lt;label htmlFor=&quot;minutes&quot;&gt;Minutes&lt;/label&gt;
                    &lt;input
                    //#2 we put the value from the const to the value so the value of the input can be equal to the state
                    value={minutes} 
                    id=&quot;minutes&quot; 
                    placeholder=&quot;Minutes&quot; 
                    type=&quot;number&quot;
                    //#3 we listen to the changes and when the input changes we do the function onChange on the top - if we delete onChange, nothing will be inputted as the default is set to 0 and no changes are listened
                    onChange={onChange} /&gt;
                    &lt;h4&gt;You want to convert {minutes}&lt;/h4&gt;
                    &lt;label htmlFor=&quot;hours&quot;&gt;Hours&lt;/label&gt;
                    &lt;input id=&quot;hours&quot; placeholder=&quot;Hours&quot; type=&quot;number&quot; /&gt;
                    &lt;/div&gt;
            );
            //html - to connect the label with input we use for and id
            //JSX - should use htmlFor instead of for and className instead of class
        };
        ReactDOM.render(&lt;App/&gt;, root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/d749c2b6-9c09-4583-a320-79d68b41818d/image.png" alt=""></p>
<h4 id="3638-state-practice">#3.6~3.8 (State Practice)</h4>
<p>converting the minutes into hours and making a reset button</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        const root = document.getElementById(&quot;root&quot;);
        function App(){
            const [minutes, setMinutes] = React.useState();
            const onChange =(event) =&gt; {
                setMinutes(event.target.value);
            };
            const reset = () =&gt; setMinutes(0);
            return(
                &lt;div&gt;
                    &lt;h1 className=&quot;hi&quot;&gt;Super Converter&lt;/h1&gt;
                    &lt;div&gt;&lt;label htmlFor=&quot;minutes&quot;&gt;Minutes&lt;/label&gt;
                    &lt;input
                    value={minutes} 
                    id=&quot;minutes&quot; 
                    placeholder=&quot;Minutes&quot; 
                    type=&quot;number&quot;
                    onChange={onChange} /&gt;&lt;/div&gt;
                    &lt;div&gt;
                    &lt;label htmlFor=&quot;hours&quot;&gt;Hours&lt;/label&gt;
                    &lt;input value={Math.round(minutes/60)} 
                    id=&quot;hours&quot; 
                    placeholder=&quot;Hours&quot; 
                    type=&quot;number&quot; /&gt; &lt;/div&gt;
                    &lt;button onClick={reset}&gt;Reset&lt;/button&gt;
                    &lt;/div&gt;
            );
        };
        ReactDOM.render(&lt;App/&gt;, root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<p>flipping to also convert hours into minutes</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        const root = document.getElementById(&quot;root&quot;);
        function App(){
            const [minutes, setMinutes] = React.useState();
            //#1 flipped is just a false / true data
            //by default flipped is false, so if flipped is false then my hours should be disabled and minutes should not be disabled
            const [flipped, setFlipped] = React.useState(false);
            const onChange =(event) =&gt; {
                setMinutes(event.target.value);
            };
            const reset = () =&gt; setMinutes(0);
            //#2 when we click on the button Flip we are running the function onFlip which will take the current value and return the opposite value
            const onFlip =() =&gt; {
                reset();
                setFlipped((current)=&gt;!current)
            };
            return(
                &lt;div&gt;
                    &lt;h1 className=&quot;hi&quot;&gt;Super Converter&lt;/h1&gt;
                    &lt;div&gt;&lt;label htmlFor=&quot;minutes&quot;&gt;Minutes&lt;/label&gt;
                    &lt;input
                    value={flipped ? minutes*60 :minutes} 
                    id=&quot;minutes&quot; 
                    placeholder=&quot;Minutes&quot; 
                    type=&quot;number&quot;
                    onChange={onChange}
                    disabled={flipped} /&gt;&lt;/div&gt;
                    &lt;div&gt;
                    &lt;label htmlFor=&quot;hours&quot;&gt;Hours&lt;/label&gt;
                    &lt;input value={flipped? minutes : Math.round(minutes/60)} 
                    id=&quot;hours&quot; 
                    placeholder=&quot;Hours&quot; 
                    type=&quot;number&quot;
                    onChange={onChange}
                    disabled={!flipped} /&gt; &lt;/div&gt;
                    &lt;button onClick={reset}&gt;Reset&lt;/button&gt;
                    &lt;button onClick={onFlip}&gt;{flipped ? &quot;Turn back&quot; : &quot;Flip&quot;}&lt;/button&gt;
                    &lt;/div&gt;
            );
            //conversion should only happen when I write minutes, so if we are flipped I just want to show the current value and if we are not flipped, I want to see the converted mathround value
        };
        ReactDOM.render(&lt;App/&gt;, root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<h4 id="39-final-state-practice">#3.9 (Final State Practice)</h4>
<p>making a menu for the user to choose which units to convert</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        const root = document.getElementById(&quot;root&quot;);
        function MinutesToHours(){
            const [minutes, setMinutes] = React.useState();
            const [flipped, setFlipped] = React.useState(false);
            const onChange =(event) =&gt; {
                setMinutes(event.target.value);
            };
            const reset = () =&gt; setMinutes(0);
            const onFlip =() =&gt; {
                reset();
                setFlipped((current)=&gt;!current)
            };
            return(
                &lt;div&gt;
                    &lt;div&gt;&lt;label htmlFor=&quot;minutes&quot;&gt;Minutes&lt;/label&gt;
                    &lt;input
                    value={flipped ? minutes*60 :minutes} 
                    id=&quot;minutes&quot; 
                    placeholder=&quot;Minutes&quot; 
                    type=&quot;number&quot;
                    onChange={onChange}
                    disabled={flipped} /&gt;&lt;/div&gt;
                    &lt;div&gt;
                    &lt;label htmlFor=&quot;hours&quot;&gt;Hours&lt;/label&gt;
                    &lt;input value={flipped? minutes : Math.round(minutes/60)} 
                    id=&quot;hours&quot; 
                    placeholder=&quot;Hours&quot; 
                    type=&quot;number&quot;
                    onChange={onChange}
                    disabled={!flipped} /&gt; &lt;/div&gt;
                    &lt;button onClick={reset}&gt;Reset&lt;/button&gt;
                    &lt;button onClick={onFlip}&gt;{flipped ? &quot;Turn back&quot; : &quot;Flip&quot;}&lt;/button&gt;
                    &lt;/div&gt;
            );
        };
        function KmToMile(){
            const [kilometer, setKilometer] = React.useState(0);
      const onChange = (event) =&gt; {
        const { value } = event.target;
        setKilometer(value);
      };
      const [inverted, setInverted] = React.useState(true);
      const reset = () =&gt; setKilometer(0);
      const onInvert = () =&gt; {
        reset();
        setInverted((data) =&gt; !data);
      };
      return (
        &lt;div&gt;
          &lt;div&gt;
            &lt;label htmlFor=&quot;kilometer&quot; value={kilometer}&gt;
              Kilometer
            &lt;/label&gt;
            &lt;input
              type=&quot;number&quot;
              id=&quot;kilometer&quot;
              placeholder=&quot;Kilometer&quot;
              disabled={!inverted}
              onChange={onChange}
              value={inverted ? kilometer : kilometer / 0.62137}
            /&gt;
          &lt;/div&gt;
          &lt;div&gt;
            &lt;label htmlFor=&quot;Mile&quot;&gt;Mile&lt;/label&gt;
            &lt;input
              id=&quot;Mile&quot;
              type=&quot;number&quot;
              placeholder=&quot;Mile&quot;
              value={inverted ? kilometer * 0.62137 : kilometer}
              onChange={onChange}
              disabled={inverted}
            /&gt;
          &lt;/div&gt;
          &lt;button onClick={reset}&gt;Reset&lt;/button&gt;
          &lt;button onClick={onInvert}&gt;
            {inverted ? &quot;Invert&quot; : &quot;Turn back&quot;}
          &lt;/button&gt;
        &lt;/div&gt;
      );
    };
        //just dividing and conquering - App is rending to root div
        function App(){
            //#2 we know what number has been chosen and we put the value in the state by using the setIndex, the modifier function will refresh with the new data
            //by default the value index is xx
            const [index, setIndex] = React.useState(&quot;xx&quot;)
            const onSelect = (event) =&gt; {
                setIndex(event.target.value);
            }
            return(
                //#1 we are listening to the changed event of which value the user has selected
                &lt;div&gt;
                    &lt;h1 &gt;Super Converter&lt;/h1&gt;
                    &lt;select value={index} onChange={onSelect}&gt;
                        &lt;option value =&quot;xx&quot;&gt;Select your units&lt;/option&gt;
                        &lt;option value=&quot;0&quot;&gt;Minutes &amp; Hours&lt;/option&gt;    
                        &lt;option value=&quot;1&quot;&gt;Km &amp; Miles&lt;/option&gt;    
                    &lt;/select&gt;
                    &lt;hr/&gt;
                    {index === &quot;xx&quot; ? &quot;Please select your units&quot; : null}
                    {index === &quot;0&quot; ? &lt;MinutesToHours/&gt; : null}
                    {index === &quot;1&quot; ? &lt;KmToMile/&gt; : null}
                    &lt;/div&gt;
            );
        };
        ReactDOM.render(&lt;App/&gt;, root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/6b353582-5542-463c-b4cf-40c1e843760d/image.png" alt=""></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[ReactJS Day3]]></title>
            <link>https://velog.io/@jisu_lee/ReactJS-Day3</link>
            <guid>https://velog.io/@jisu_lee/ReactJS-Day3</guid>
            <pubDate>Sun, 30 Apr 2023 01:46:47 GMT</pubDate>
            <description><![CDATA[<p>오늘은 노마드코더 스터디 세 번째 시간입니다. 오늘도 화이탱!
<img src="https://velog.velcdn.com/images/jisu_lee/post/3787b823-8e86-4ce0-a12b-27985165b69a/image.png" alt=""></p>
<h4 id="30-understanding-state">#3.0 (Understanding State)</h4>
<p>• data that changes is the state (e.g., increasing the counter)
• reactJS only changes the only component that needs to be changed and changes only the thing that is updated (e.g., only the number of clicks changes not the whole button - vanilla js changes the whole span of button with click numbers)
• The following way is having the initial value and rerendering everytime we click the button --&gt; not a good way</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        const root = document.getElementById(&quot;root&quot;);
       let counter = 0;
        function countUp(){
            counter = counter +1;
           render();
        }
        function render(){
            ReactDOM.render(&lt;Container/&gt;,root);
        }

        const Container = () =&gt; (
            &lt;div&gt;
           &lt;h3&gt;Total clicks: {counter}&lt;/h3&gt;
           &lt;button onClick={countUp}&gt;Click me&lt;/button&gt;
            &lt;/div&gt; 
            );
        //rendering the container only once so we need to recall again to update the number
        render();

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<h4 id="3132-setstate">#3.1~3.2 (setState)</h4>
<p>ways to match each elements with the corresponding item </p>
<pre><code class="language-html">const food=[&quot;tomato&quot;,&quot;potato&quot;]
const [myFavFood, mySecondFavFood]=food;
//console에 myFavFood를 치면 tomato가 나옴

const x = [1,2,3]
const [a,b,c]=x;
/console에 a를 치면 1이 나옴</code></pre>
<p>code before making a modifier function</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        const root = document.getElementById(&quot;root&quot;);
        function App(){
            const [counter, modifier] =React.useState(0);
            return(
                &lt;div&gt;
                    &lt;h3&gt;Total Clicks: {counter}&lt;/h3&gt;
                    &lt;button&gt;Click me&lt;/button&gt;
                &lt;/div&gt;
            );
        };
        ReactDOM.render(&lt;App/&gt;, root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<p>code after making the setCounter (=modifier) function 
• when you use the setCounter function, the whole component will be rendered again with the modified value
• the setCounter function will give data to the counter and trigger the render function</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        const root = document.getElementById(&quot;root&quot;);
        function App(){
            const [counter, setCounter] =React.useState(0);
            //useState: will give data - counter, and will give function to modify the data - modifier (setCounter)
            const onClick = () =&gt; {
                //modifier function will change the value and trigger render again (rerender)
                setCounter(counter+1);
            };
            return(
                &lt;div&gt;
                    &lt;h3&gt;Total Clicks: {counter}&lt;/h3&gt;
                    &lt;button onClick={onClick}&gt;Click me&lt;/button&gt;
                &lt;/div&gt;
            );
        };
        ReactDOM.render(&lt;App/&gt;, root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<h4 id="34-state-functions">#3.4 (State Functions)</h4>
<p>first way of changing the state is to give a fixed value</p>
<pre><code class="language-html"> const root = document.getElementById(&quot;root&quot;);
        function App(){
            const [counter, setCounter] =React.useState(0);
            const onClick = () =&gt; {
                setCounter(987);
            };
            return(
                &lt;div&gt;
                    &lt;h3&gt;Total Clicks: {counter}&lt;/h3&gt;
                    &lt;button onClick={onClick}&gt;Click me&lt;/button&gt;
                &lt;/div&gt;
            );
        };
        ReactDOM.render(&lt;App/&gt;, root);</code></pre>
<p>output:
<img src="https://velog.velcdn.com/images/jisu_lee/post/01957ce3-dcf4-4704-a676-11ed66f01820/image.png" alt=""></p>
<p>second way of changing the state is to utilize a function with &#39;current&#39;</p>
<pre><code class="language-html">const root = document.getElementById(&quot;root&quot;);
        function App(){
            const [counter, setCounter] =React.useState(0);
            const onClick = () =&gt; {
                //setCounter(counter + 1);
                //if you want to calculate the next state based on the current state, then you need to use the function
                setCounter((current) =&gt; current +1);
            };
            return(
                &lt;div&gt;
                    &lt;h3&gt;Total Clicks: {counter}&lt;/h3&gt;
                    &lt;button onClick={onClick}&gt;Click me&lt;/button&gt;
                &lt;/div&gt;
            );
        };
        ReactDOM.render(&lt;App/&gt;, root);</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[ReactJS Day2]]></title>
            <link>https://velog.io/@jisu_lee/ReactJS-Day2</link>
            <guid>https://velog.io/@jisu_lee/ReactJS-Day2</guid>
            <pubDate>Sun, 23 Apr 2023 13:30:39 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/jisu_lee/post/92f387b8-dad8-47b0-8137-8b7b209b320d/image.png" alt="">
오늘은 노마드코더 ReactJS 수강 두 번째 날입니다! 내일 출근 전까지 화이탱구리구리</p>
<h4 id="22-our-first-react-element">#2.2 (Our First React Element)</h4>
<p>writing the code (e.g., making a span in html) in a hard way using ReactJS</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
    &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script&gt;
        //ReactJS is a tool that makes the website/UI interactive and React Dom is what put the react in the html
        const root = document.getElementById(&quot;root&quot;);
        //second item is the property, can be the class or the id name, give an id to the span called sexy-span
        //third item is the content of the span
        const span = React.createElement(
        &quot;span&quot;,
        {id:&quot;sexy-span&quot;, style: {color:&quot;red&quot;}},
        &quot;Hello I am a span&quot;);
        //render is used to show it to the user -&gt; render the span inside of the root
        ReactDOM.render(span,root);
        //first write in the html, grab it to javascript and revise it
        //ReactJS inverse it by writing it first and putting it to the html
        //ReactJS will be updated to change the html
    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<h4 id="23-events-in-react">#2.3 (Events in React)</h4>
<p>creating an eventlistener using ReactJS</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
    &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script&gt;
        const root = document.getElementById(&quot;root&quot;);
        const h3 = React.createElement(&quot;h3&quot;,
        {onMouseEnter: () =&gt; console.log(&quot;mouse enter&quot;)},
        &quot;Hello I am a span&quot;);
        const btn = React.createElement(&quot;button&quot;,
          //eventlistner and background color is also an example of property
          //ReactJS is smart to know what props shoud go into html (e.g., id, color) and what should not go into html (e.g., eventlistener)
        {onClick: () =&gt; console.log(&quot;i am click&quot;),
            style: {backgroundColor:&quot;tomato&quot;}},
        &quot;Click me&quot;);
        const container = React.createElement(&quot;div&quot;,null,[h3,btn]);
        ReactDOM.render(container,root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<h4 id="2526-jsx">#2.5~2.6 (JSX)</h4>
<p>using JSX to shorten the lines
JSX is a syntax expanded from JavaScript -&gt; makes a React element and looks similar to HTML</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
    &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script scr=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        const root = document.getElementById(&quot;root&quot;);
        const Title = (
            &lt;h3 id=&quot;Title&quot; onMouseEnter={() =&gt; console.log(&quot;mouse enter&quot;)}&gt;
                Hello I am a title
                &lt;/h3&gt;
            );
        const Button = &lt;button style={{backgroundColor: &quot;tomato&quot;,}} 
        onClick={() =&gt; console.log(&quot;I am clicked&quot;)}
        &gt;
        Click me&lt;/button&gt;
        const container = React.createElement(&quot;div&quot;,null,[Title,Button]);
        ReactDOM.render(container,root);

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<p>making a function and rendering it to html</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;
    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/@babel/standalone/babel.min.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/babel&quot;&gt;
        const root = document.getElementById(&quot;root&quot;);
        const Title = () =&gt; (
            &lt;h3 id=&quot;title&quot; onMouseEnter={() =&gt; console.log(&quot;mouse enter&quot;)}&gt;
                Hello I am a title
                &lt;/h3&gt;
            );
        //making a function
        const Button = () =&gt; (
        &lt;button style={{backgroundColor: &quot;tomato&quot;,}} 
        onClick={() =&gt; console.log(&quot;I am clicked&quot;)}
        &gt;
        Click me&lt;/button&gt; 
        );
        const Container = () =&gt; (
            &lt;div&gt;
           &lt;Title /&gt; &lt;Button /&gt;
            &lt;/div&gt; 
            );
        ReactDOM.render(&lt;Container/&gt;,root);
        //the first letter of the component should be uppercase, if it&#39;s lowercase then ReactJS and JSX will think it as a html tag

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
<p>function can be wrote in the following two ways</p>
<pre><code class="language-html">const Button = () =&gt; ()
function Button() { return }</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[ReactJS Day1]]></title>
            <link>https://velog.io/@jisu_lee/ReactJS-Day1</link>
            <guid>https://velog.io/@jisu_lee/ReactJS-Day1</guid>
            <pubDate>Sat, 15 Apr 2023 03:44:04 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/jisu_lee/post/8d39ad6c-23b2-402b-a9d6-d05ee9ca1637/image.png" alt="">
노마드코더 강의로 ReactJS 스터디를 시작하였습니다! 새로운 언어를 배우는 만큼 큰 설렘을 가지고 한 번 열심히 수강해보도록 하겠습니다! 화이탱..구리구리</p>
<h4 id="1113-why-react">#1.1~1.3 (Why React)</h4>
<ol>
<li>누가 이 기술을 사용하는지, 기술의 규모는 어떤지를 파악하는 것이 중요 --&gt; 상위 1만 개의 웹사이트 중 44.76%는 ReactJS를 사용함 (e.g., Airbnb, Facebook, Instagram, Netflix)</li>
<li>페이스북이 ReactJS를 만들었으며, 그들의 웹사이트도 ReactJS로 작업하였으며, 이를 개선하기 위해 자금을 투자하고 있음</li>
<li>큰 커뮤니티를 가지고 있음. ReactJS는 Javascript와 비슷하기 때문에 Javascript의 커뮤니티를 함께 빌려왔기 때문에 커뮤니티가 아주 거대함</li>
</ol>
<h4 id="2021-introductionbefore-react">#2.0~2.1 (Introduction/Before React)</h4>
<p>ReactJS makes the UI more interactive --&gt; makes interactivity in the website very simple</p>
<p><strong>Building vanillaJS to compare it with ReactJS</strong></p>
<p>Vanilla JS using only html - making the button</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;button id=&quot;btn&quot;&gt;Click me&lt;/button&gt;
    &lt;/body&gt;
    &lt;script&gt;
        const button = document.getElementById(&quot;btn&quot;);
        function handleClick(){
            console.log(&quot;I have been clicked&quot;);
        }
        button.addEventListener(&quot;click&quot;,handleClick);
    &lt;/script&gt;

&lt;/html&gt;</code></pre>
<p>Vanilla JS only using html - displaying clicks</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;
        &lt;button id=&quot;btn&quot;&gt;Click me&lt;/button&gt;
    &lt;/body&gt;
    &lt;!--step #1 create html, step #2 grab it from javascript, step #3 listen for events, step #4 update the data, step #5 update the html as well--&gt;
    &lt;span&gt;Total clicks: 0&lt;/span&gt;
    &lt;script&gt;
        let counter = 0;
        const span = document.querySelector(&quot;span&quot;);
        const button = document.getElementById(&quot;btn&quot;);
        function handleClick(){
            counter = counter +1;
            span.innerText=`Total clicks: ${counter}`;
        }
        button.addEventListener(&quot;click&quot;,handleClick);
    &lt;/script&gt;

&lt;/html&gt;</code></pre>
<p>importing react and react-dom into html</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;body&gt;

    &lt;/body&gt;
    &lt;script src=&quot;https://unpkg.com/react@17.0.2/umd/react.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js&quot;&gt;&lt;/script&gt;
    &lt;script&gt;

    &lt;/script&gt;
&lt;/html&gt;</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[Javascript Day7]]></title>
            <link>https://velog.io/@jisu_lee/Javascript-Day7</link>
            <guid>https://velog.io/@jisu_lee/Javascript-Day7</guid>
            <pubDate>Sat, 25 Mar 2023 03:02:18 GMT</pubDate>
            <description><![CDATA[<p>오늘은 노마드코더 자바스크립트 마지막 스터디입니다! 드디어 &#39;바닐라 JS로 크롬 앱 만들기&#39; 강의도 끝이 났네요!
<img src="https://velog.velcdn.com/images/jisu_lee/post/4c91bcdd-d183-4e9e-850d-4e7639a3c5d5/image.png" alt=""></p>
<h4 id="7678-deleting-to-dos">#7.6~7.8 (Deleting To Dos)</h4>
<p>saving objects with text and id, able to delete based on the ids (adding item to the array by using push)</p>
<pre><code class="language-javascript">코드를 const toDoForm = document.getElementById(&quot;todo-form&quot;);
const toDoInput = toDoForm.querySelector(&quot;input&quot;);
const toDoList = document.getElementById(&quot;todo-list&quot;);

const TODOS_KEY =&quot;todos&quot;;

let toDos = [];

function saveToDos(){
    localStorage.setItem(TODOS_KEY,JSON.stringify(toDos));
}


function deleteToDo(event){
    const li = event.target.parentElement;
      //before deleting li from the screen we can get the id of the li
      console.log(li.id);
    li.remove();

}

function paintToDo(newToDo){
    const li = document.createElement(&quot;li&quot;);
    //&lt;li id=&quot;random number&quot;&gt;&lt;/li&gt; will be in the html
    li.id=newToDo.id;
    const span = document.createElement(&quot;span&quot;);
    //display only the text from the object
    span.innerText = newToDo.text;
    const button = document.createElement(&quot;button&quot;);
    button.innerText =&quot;X&quot;;
    button.addEventListener(&quot;click&quot;,deleteToDo);
    li.appendChild(span);
    li.appendChild(button);
    toDoList.appendChild(li);
}


function handleToDoSubmit(event){
    event.preventDefault();
    const newToDo = toDoInput.value;
    toDoInput.value=&quot;&quot;;
    //instead of pushing just the text, now I want to push the object (id and text)
    const newTodoObj = {
        text:newToDo,
        //generate random numbers for the id (identity each item with the item)
        id:Date.now(),
    }
    toDos.push(newTodoObj);
    //called by the object
    paintToDo(newTodoObj);
    saveToDos();
}

toDoForm.addEventListener(&quot;submit&quot;,handleToDoSubmit);

const savedToDos = localStorage.getItem(TODOS_KEY);

if(savedToDos !==null){
    const parsedToDos = JSON.parse(savedToDos);
    toDos=parsedToDos;
    parsedToDos.forEach(paintToDo);
}</code></pre>
<p>how to use filter function</p>
<pre><code class="language-javascript">//old array stays but we are creating the new array excluding the item we want to delete
function sexyFilter(){

}
//filter will can sexyFilter() for 1,2,3,4 (similar to foreach)
[1,2,3,4].filter(sexyfilter)
//sexyFilter() should return true if you want to keep the items in the array, if false that item will not be included in the new array
//the new array will keep only the items that is true

function sexyFilter(){return true}
[1,2,3,4].filter(sexyFilter)
//then the output will be [1,2,3,4]

function sexyFilter(){return true}
[1,2,3,4].filter(sexyFilter)
//then the output will be []

function sexyFilter(item){return item !==3}
[1,2,3,4].filter(sexyFilter)
//return if the item is not 3, the output will be [1,2,4]
//1 is returned because the item is not equaled to 3 (true)

const todos = [{text:&quot;lala&quot;},{text:&quot;lolo&quot;}]
function sexyFilter(todo){return todo.text !==&quot;lala&quot;}
todos.filter(sexyFilter)
//the output will be {text:&quot;lolo&quot;}

const todos = [{text:&quot;lalalala&quot;}, {text:&quot;lolololo&quot;}];
todos.filter(item =&gt; item.text !== &quot;lolololo&quot;);
//using arrow</code></pre>
<p>deleting item from the array</p>
<pre><code class="language-javascript">const toDoForm = document.getElementById(&quot;todo-form&quot;);
const toDoInput = toDoForm.querySelector(&quot;input&quot;);
const toDoList = document.getElementById(&quot;todo-list&quot;);

const TODOS_KEY =&quot;todos&quot;;

let toDos = [];

function saveToDos(){
    localStorage.setItem(TODOS_KEY,JSON.stringify(toDos));
}


function deleteToDo(event){
    const li = event.target.parentElement;
    li.remove();
    //filter doesn&#39;t modify the original array but keeps making new arrays
    //calling for every toDo in the database
    //keep the toDo that does not have the id same with the ones we clicked to delete
    //toDo.id is a number and li.id is a string
    toDos=toDos.filter(toDo =&gt; toDo.id !== parseInt(li.id));
    saveToDos();
}

function paintToDo(newToDo){
    const li = document.createElement(&quot;li&quot;);
    //&lt;li id=&quot;random number&quot;&gt;&lt;/li&gt; will be in the html
    li.id=newToDo.id;
    const span = document.createElement(&quot;span&quot;);
    //display only the text from the object
    span.innerText = newToDo.text;
    const button = document.createElement(&quot;button&quot;);
    button.innerText =&quot;X&quot;;
    button.addEventListener(&quot;click&quot;,deleteToDo);
    li.appendChild(span);
    li.appendChild(button);
    toDoList.appendChild(li);
}


function handleToDoSubmit(event){
    event.preventDefault();
    const newToDo = toDoInput.value;
    toDoInput.value=&quot;&quot;;
    //instead of pushing just the text, now I want to push the object (id and text)
    const newTodoObj = {
        text:newToDo,
        //generate random numbers for the id (identity each item with the item)
        id:Date.now(),
    }
    toDos.push(newTodoObj);
    //called by the object
    paintToDo(newTodoObj);
    saveToDos();
}

toDoForm.addEventListener(&quot;submit&quot;,handleToDoSubmit);

const savedToDos = localStorage.getItem(TODOS_KEY);

if(savedToDos !==null){
    const parsedToDos = JSON.parse(savedToDos);
    toDos=parsedToDos;
    //forEach function is executing the painToDo function for each item (object) on the aray parsedToDos
    parsedToDos.forEach(paintToDo);
}</code></pre>
<p>the output when we enter 1,2,3 and delete 2,3
<img src="https://velog.velcdn.com/images/jisu_lee/post/a73a27cc-0d0c-4d5e-8f87-b22ef3135bec/image.png" alt=""></p>
<h4 id="80-geolocation">#8.0 (Geolocation)</h4>
<p>making the new weather.js</p>
<pre><code class="language-html"> &lt;script src=&quot;js/weather.js&quot;&gt;&lt;/script&gt;     </code></pre>
<p>getting the location of the user</p>
<pre><code class="language-javascript">function onGeoOk(position){
    const lat = position.coords.latitude;
    const lng = position.coords.longitude;
    console.log(&quot;You live in&quot;,lat,lng);
}

function onGeoError(){
    alert(&quot;Can&#39;t find you. No weather for you.&quot;);
}

navigator.geolocation.getCurrentPosition(onGeoOk,onGeoError);</code></pre>
<h4 id="81-weather-api">#8.1 (Weather API)</h4>
<p>creating the span for html</p>
<pre><code class="language-html">   &lt;div id=&quot;weather&quot;&gt;
      &lt;span&gt;&lt;/span&gt;
      &lt;span&gt;&lt;/span&gt;
   &lt;/div&gt;</code></pre>
<p>getting the weather API to display the city and the weather (temperature)</p>
<pre><code class="language-javascript">const API_KEY =&quot;bf6a290229ac2c9da9a4ca900b69d269&quot;;

function onGeoOk(position){
    const lat = position.coords.latitude;
    const lon = position.coords.longitude;
    console.log(&quot;You live in&quot;,lat,lon);
    const url =`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&amp;lon=${lon}&amp;appid=${API_KEY}&amp;units=metric`;
    //calling the url
    fetch(url)
    .then((response) =&gt; response.json())
    .then((data)=&gt;{
        //getting the first span for weather
        const weatherContainer = document.querySelector(&quot;#weather span:first-child&quot;);
        //getting the second span in the html for city
        const cityContainer = document.querySelector(&quot;#weather span:last-child&quot;);
        //filling the span with city name
        city.innerText= data.name; 
        //filling the span with weather (and temperature from the main)
        weather.innerText =  `${data.weather[0].main} / ${data.main.temp}`;
    });
}

function onGeoError(){
    alert(&quot;Can&#39;t find you. No weather for you.&quot;);
}

navigator.geolocation.getCurrentPosition(onGeoOk,onGeoError);</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[Javascript Day6]]></title>
            <link>https://velog.io/@jisu_lee/Javascript-Day6</link>
            <guid>https://velog.io/@jisu_lee/Javascript-Day6</guid>
            <pubDate>Mon, 13 Mar 2023 13:51:30 GMT</pubDate>
            <description><![CDATA[<p>오늘은 노마드코더 강의를 수강한지 벌써 여섯 번째 날입니다.
<img src="https://velog.velcdn.com/images/jisu_lee/post/d74dbacc-2fd2-4f40-a902-cdee91387852/image.png" alt=""></p>
<h4 id="70-setup--71-adding-todos">#7.0 (Setup) &amp; #7.1 (Adding ToDos)</h4>
<p>html code</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;css/style.css&quot;&gt;
    &lt;title&gt;Momentum&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
   &lt;form class=&quot;hidden&quot; id=&quot;login-form&quot;&gt;
   &lt;/form&gt;
   &lt;h1 id=&quot;greeting&quot; class=&quot;hidden&quot;&gt;&lt;/h1&gt;
   &lt;form id=&quot;todo-form&quot;&gt; &lt;!--form to type the todos--&gt;
      &lt;input type=&quot;text&quot; placeholder=&quot;Write a To Do and Press Enter&quot; required /&gt;
   &lt;/form&gt;
  &lt;!--list to write the todos--&gt;
   &lt;ul id=&quot;todo-list&quot;&gt; 
   &lt;!--we are going to be creating &lt;li&gt;s from the javascript--&gt;
   &lt;/ul&gt;
   &lt;h2 id=&quot;clock&quot;&gt;00:00:00&lt;/h2&gt;
   &lt;div id=&quot;quote&quot;&gt;
      &lt;span&gt;&lt;/span&gt;
      &lt;span&gt;&lt;/span&gt;
   &lt;/div&gt;
   &lt;script src=&quot;js/greetings.js&quot;&gt;&lt;/script&gt;
   &lt;script src=&quot;js/clock.js&quot;&gt;&lt;/script&gt;
   &lt;script src=&quot;js/quotes.js&quot;&gt;&lt;/script&gt;
   &lt;script src=&quot;js/background.js&quot;&gt;&lt;/script&gt;
   &lt;script src=&quot;js/todo.js&quot;&gt;&lt;/script&gt;            
   &lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>javascript code (we are able to write new todos but we are not able to delete them)</p>
<pre><code class="language-javascript">const toDoForm = document.getElementById(&quot;todo-form&quot;);
//const toDoInput = document.getElementById(&quot;#todo-form input&quot;);
const toDoInput = toDoForm.querySelector(&quot;input&quot;);
const toDoList = document.getElementById(&quot;todo-list&quot;);

function paintToDo(newToDo){
    const li = document.createElement(&quot;li&quot;);
    const span = document.createElement(&quot;span&quot;);
    //li has a child called span, we want to put &lt;span&gt; inside the &lt;li&gt;
    li.appendChild(span);
      //inside &lt;span&gt;&lt;/span&gt; will be the text of newToDo
    span.innerText = newToDo;
      //put the &lt;li&gt; and &lt;span&gt; inside the &lt;ul&gt;
    toDoList.appendChild(li);
}

//javascript will give the first event that happend as an argument
function handleToDoSubmit(event){
    event.preventDefault();
    //newToDo represents the value of the input before we empty the input
    const newToDo = toDoInput.value;
    toDoInput.value=&quot;&quot;;
      //call the function painToDo will the value of the input
    paintToDo(newToDo);
}

toDoForm.addEventListener(&quot;submit&quot;,handleToDoSubmit);</code></pre>
<h4 id="72-deleting-to-dos">#7.2 (Deleting To Dos)</h4>
<p>javascript code to delete the todos</p>
<pre><code class="language-javascript">const toDoForm = document.getElementById(&quot;todo-form&quot;);
const toDoInput = toDoForm.querySelector(&quot;input&quot;);
const toDoList = document.getElementById(&quot;todo-list&quot;);

//when clicked the button, delete todo
function deleteToDo(event){
      //we don&#39;t know which button was clicked so we are specifying to see which button was clicked
    const li = event.target.parentElement;
    li.remove();

}

/*we want to do
&lt;ul&gt;
    &lt;li&gt;
        &lt;span&gt; todo1 &lt;/span&gt;
        &lt;button&gt;X&lt;/button&gt;
    &lt;/li&gt;
&lt;/ul&gt; */

function paintToDo(newToDo){
    const li = document.createElement(&quot;li&quot;);
    const span = document.createElement(&quot;span&quot;);
    span.innerText = newToDo;
      //create a button shaped X
    const button = document.createElement(&quot;button&quot;);
    button.innerText =&quot;X&quot;;
    button.addEventListener(&quot;click&quot;,deleteToDo);
    li.appendChild(span);
      //want to add the button inside the &lt;li&gt;
    li.appendChild(button);
    toDoList.appendChild(li);
}


function handleToDoSubmit(event){
    event.preventDefault();
    const newToDo = toDoInput.value;
    toDoInput.value=&quot;&quot;;
    paintToDo(newToDo);
}

toDoForm.addEventListener(&quot;submit&quot;,handleToDoSubmit);</code></pre>
<h4 id="73-saving-to-dos">#7.3 (Saving To Dos)</h4>
<p>how to save todos in the local storage - javascript code</p>
<pre><code class="language-javascript">const toDoForm = document.getElementById(&quot;todo-form&quot;);
const toDoInput = toDoForm.querySelector(&quot;input&quot;);
const toDoList = document.getElementById(&quot;todo-list&quot;);

//creating an array
const toDos = [];

function saveToDos(){
      //local storage does not allow saving arrays, but only strings
      //JSON.stringify will take whatever javascript code and turn that into a string
    localStorage.setItem(&quot;todos&quot;,JSON.stringify(toDos));
}


function deleteToDo(event){
    const li = event.target.parentElement;
    li.remove();

}

function paintToDo(newToDo){
    const li = document.createElement(&quot;li&quot;);
    const span = document.createElement(&quot;span&quot;);
    span.innerText = newToDo;
    const button = document.createElement(&quot;button&quot;);
    button.innerText =&quot;X&quot;;
    button.addEventListener(&quot;click&quot;,deleteToDo);
    li.appendChild(span);
    li.appendChild(button);
    toDoList.appendChild(li);
}


function handleToDoSubmit(event){
    event.preventDefault();
    const newToDo = toDoInput.value;
    toDoInput.value=&quot;&quot;;
      //push the newToDo (the input) to the array toDos
    toDos.push(newToDo);
      //disply on the screen
    paintToDo(newToDo);
    saveToDos();
}

toDoForm.addEventListener(&quot;submit&quot;,handleToDoSubmit);</code></pre>
<h4 id="7475-loading-to-dos">#7.4~7.5 (Loading To Dos)</h4>
<p>first way of writing a javascript code to load todos</p>
<pre><code class="language-javascript">const toDoForm = document.getElementById(&quot;todo-form&quot;);
const toDoInput = toDoForm.querySelector(&quot;input&quot;);
const toDoList = document.getElementById(&quot;todo-list&quot;);
//make the key to not make mistakes
const TODOS_KEY =&quot;todos&quot;;

const toDos = [];

function saveToDos(){
    localStorage.setItem(TODOS_KEY,JSON.stringify(toDos));
}


function deleteToDo(event){
    const li = event.target.parentElement;
    li.remove();

}

function paintToDo(newToDo){
    const li = document.createElement(&quot;li&quot;);
    const span = document.createElement(&quot;span&quot;);
    span.innerText = newToDo;
    const button = document.createElement(&quot;button&quot;);
    button.innerText =&quot;X&quot;;
    button.addEventListener(&quot;click&quot;,deleteToDo);
    li.appendChild(span);
    li.appendChild(button);
    toDoList.appendChild(li);
}


function handleToDoSubmit(event){
    event.preventDefault();
    const newToDo = toDoInput.value;
    toDoInput.value=&quot;&quot;;
    toDos.push(newToDo);
    paintToDo(newToDo);
    saveToDos();
}

toDoForm.addEventListener(&quot;submit&quot;,handleToDoSubmit);

function sayHello(item){
      // if i write a, b, c, then it will display this is the turn of a, this is the turn of be, this is the turn of c
    console.log(&quot;this is the turn of&quot;, item);
}


const savedToDos = localStorage.getItem(TODOS_KEY);

//savedToDos could be null if there is nothing in the local storage
if(savedToDos !==null){
      //turn the strings to an array
    const parsedToDos = JSON.parse(savedToDos);
      //for each items in the array Todos we will run the function sayHello
    parsedToDos.forEach(sayHello);
}</code></pre>
<p>shorter way to write the javascript code</p>
<pre><code class="language-javascript">if(savedToDos !==null){
    const parsedToDos = JSON.parse(savedToDos);
    parsedToDos.forEach((item)=&gt; console.log(&quot;this is the turn of&quot;,item));
}</code></pre>
<p>when we refresh the page, the todos in saved in the local storage is also refreshed, so we want to keep them</p>
<pre><code class="language-javascript">const toDoForm = document.getElementById(&quot;todo-form&quot;);
const toDoInput = toDoForm.querySelector(&quot;input&quot;);
const toDoList = document.getElementById(&quot;todo-list&quot;);

const TODOS_KEY =&quot;todos&quot;;

//change the const to let so the array can be accumulative
let toDos = [];

function saveToDos(){
    localStorage.setItem(TODOS_KEY,JSON.stringify(toDos));
}


function deleteToDo(event){
    const li = event.target.parentElement;
    li.remove();

}

function paintToDo(newToDo){
    const li = document.createElement(&quot;li&quot;);
    const span = document.createElement(&quot;span&quot;);
    span.innerText = newToDo;
    const button = document.createElement(&quot;button&quot;);
    button.innerText =&quot;X&quot;;
    button.addEventListener(&quot;click&quot;,deleteToDo);
    li.appendChild(span);
    li.appendChild(button);
    toDoList.appendChild(li);
}


function handleToDoSubmit(event){
    event.preventDefault();
    const newToDo = toDoInput.value;
    toDoInput.value=&quot;&quot;;
    toDos.push(newToDo);
    paintToDo(newToDo);
    saveToDos();
}

toDoForm.addEventListener(&quot;submit&quot;,handleToDoSubmit);

const savedToDos = localStorage.getItem(TODOS_KEY);

if(savedToDos !==null){
    const parsedToDos = JSON.parse(savedToDos);
      //restore the previous todos
    toDos=parsedToDos;
      //call the function painToDo for each input in the local storage, displaying everything inside the local storage
    parsedToDos.forEach(paintToDo);
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[Javascript Day5]]></title>
            <link>https://velog.io/@jisu_lee/Javascript-Day5</link>
            <guid>https://velog.io/@jisu_lee/Javascript-Day5</guid>
            <pubDate>Sat, 04 Mar 2023 10:30:19 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/jisu_lee/post/473630d9-419d-4ac4-9463-5379411471df/image.png" alt="">
오늘은 노마드코더 스터디를 시작한지 벌써 다섯 번째 날입니다. 이제 두 번만 더 들으면 자바스크립트에서 새로운 언어로 넘어갈 수 있답니다. 그럼..화이탱!</p>
<h4 id="60-quotes">#6.0 (Quotes)</h4>
<pre><code class="language-javascript">const quotes =[ 
{
    quote: &quot;Be yourself; everyone else is already taken.&quot;,
    author:&quot;Oscar Wilde&quot;,
},
{
    quote:&quot;I&#39;m selfish, impatient and a little insecure. I make mistakes, I am out of control and at times hard to handle. But if you can&#39;t handle me at my worst, then you sure as hell don&#39;t deserve me at my best.&quot;,
    author:&quot;Marilyn Monroe&quot;,
},
{
    quote:&quot;Two things are infinite: the universe and human stupidity; and I&#39;m not sure about the universe.&quot;,
    author:&quot;Albert Einstein&quot;,
},
{
    quote:&quot;So many books, so little time.&quot;,
    author:&quot;Frank Zappa&quot;,
},
{
    quote:&quot;A room without books is like a body without a soul.&quot;,
    author:&quot;Marcus Tullius Cicero&quot;,
},
{
    quote:&quot;Be who you are and say what you feel, because those who mind don&#39;t matter, and those who matter don&#39;t mind.&quot;,
    author:&quot;Bernard M. Baruch&quot;,
},
{
    quote:&quot;You know you&#39;re in love when you can&#39;t fall asleep because reality is finally better than your dreams.&quot;,
    author:&quot;Dr. Seuss&quot;,
},
{
    quote:&quot;You only live once, but if you do it right, once is enough.&quot;,
    author:&quot;Mae West&quot;,
},
{
    quote:&quot;Be the change that you wish to see in the world.&quot;,
    author:&quot;Mahatma Gandhi&quot;,
},
{
    quote:&quot;In three words I can sum up everything I&#39;ve learned about life: it goes on.&quot;,
    author:&quot;Robert Frost&quot;,
}
]

const quote = document.querySelector(&quot;#quote span:first-child&quot;);
const author = document.querySelector(&quot;#quote span:last-child&quot;);

//we need a fucntion that gives a number between 0 and 9 (to get the item in the array, you need to do -1)
//Math.random gives a random number (float) between 0 and 1, so if we multiply it by 10, it gives a random number between 0 and 10
//Math.round rounds the float to integer
//Math.ceil will round to the top
//Math.floor will round to the bottom
console.log(quotes[Math.floor(Math.random()*10)]);</code></pre>
<p>however there can be more than 10 quotes, so we just the following code (get the length of the array)</p>
<pre><code class="language-javascript">console.log(quotes[Math.floor(Math.random()*quotes.length)]);</code></pre>
<p>html code</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;css/style.css&quot;&gt;
    &lt;title&gt;Momentum&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
   &lt;form class=&quot;hidden&quot; id=&quot;login-form&quot;&gt;
   &lt;/form&gt;
   &lt;h1 id=&quot;greeting&quot; class=&quot;hidden&quot;&gt;&lt;/h1&gt;
   &lt;h2 id=&quot;clock&quot;&gt;00:00:00&lt;/h2&gt;
   &lt;div id=&quot;quote&quot;&gt;
      &lt;span&gt;&lt;/span&gt;
      &lt;span&gt;&lt;/span&gt;
   &lt;/div&gt;
   &lt;script src=&quot;js/greetings.js&quot;&gt;&lt;/script&gt;
   &lt;script src=&quot;js/clock.js&quot;&gt;&lt;/script&gt;
   &lt;script src=&quot;js/quotes.js&quot;&gt;&lt;/script&gt;     
   &lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>we put the quote and the author in each &#39;span&#39;</p>
<pre><code class="language-javascript">const quotes =[ 

]

const quote = document.querySelector(&quot;#quote span:first-child&quot;);
const author = document.querySelector(&quot;#quote span:last-child&quot;);

const todaysQuote = quotes[Math.floor(Math.random()*quotes.length)];

quote.innerText = todaysQuote.quote;
author.innerText =todaysQuote.author;</code></pre>
<h4 id="61-background">#6.1 (Background)</h4>
<p>how to put a random background in the website 
javascript code</p>
<pre><code class="language-javascript">const images = [&quot;0.jpg&quot;,&quot;1.jpg&quot;,&quot;2.jpg&quot;];

const chosenImage = images[Math.floor(Math.random()*images.length)];

const bgImage = document.createElement(&quot;img&quot;);
//same thing as doing &lt;img src=&quot;img/1.jpg&quot;&gt; in html, instead of writing html first, javascript will do that for us
bgImage.src= `img/${chosenImage}`;

//appendChild will add the line to the html
document.body.appendChild(bgImage);</code></pre>
<p>html code</p>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;css/style.css&quot;&gt;
    &lt;title&gt;Momentum&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
   &lt;form class=&quot;hidden&quot; id=&quot;login-form&quot;&gt;
   &lt;/form&gt;
   &lt;h1 id=&quot;greeting&quot; class=&quot;hidden&quot;&gt;&lt;/h1&gt;
   &lt;h2 id=&quot;clock&quot;&gt;00:00:00&lt;/h2&gt;
   &lt;div id=&quot;quote&quot;&gt;
      &lt;span&gt;&lt;/span&gt;
      &lt;span&gt;&lt;/span&gt;
   &lt;/div&gt;
   &lt;script src=&quot;js/greetings.js&quot;&gt;&lt;/script&gt;
   &lt;script src=&quot;js/clock.js&quot;&gt;&lt;/script&gt;
   &lt;script src=&quot;js/quotes.js&quot;&gt;&lt;/script&gt;
   &lt;script src=&quot;js/background.js&quot;&gt;&lt;/script&gt;          
   &lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>how to put the image behind the text and change the font - css code</p>
<pre><code class="language-css">.hidden{
    display:none;
}

img {
    position:absolute;
    width:100%;
    height:100%;
    left: 0px;
    top: 0px;
    right:0px;
    bottom:0px;
    z-index: -1;
    opacity:80%;
    }

body{
font-family: &#39;Aclonica&#39;;
}

#quote{margin-top:50px;
font-size: 40px;
display: grid;
color:rgb(9, 6, 47);
font-weight: 300;
place-items: center;
text-shadow: 2px 2px 2px rgb(189, 187, 187);
z-index: 2;
text-align:center;
}

#clock{
    text-align:center;
}</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/dcfc8f2b-74f1-4247-86d6-48e392436762/image.png" alt=""></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Javascript Day4]]></title>
            <link>https://velog.io/@jisu_lee/Javascript-Day4</link>
            <guid>https://velog.io/@jisu_lee/Javascript-Day4</guid>
            <pubDate>Mon, 27 Feb 2023 12:39:27 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/jisu_lee/post/982263c2-3b92-4761-9ff3-d5c049190a9b/image.png" alt="">
오늘은 노마드코더 강의 수강 4일차입니다.</p>
<h4 id="50-intervals">#5.0 (Intervals)</h4>
<p>create a new file called clock.js and put that into the folder called &#39;js&#39;, then import them into html</p>
<pre><code class="language-html">&lt;script src=&quot;js/greetings.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;js/clock.js&quot;&gt;&lt;/script&gt; </code></pre>
<p>interval is something that you want to happen every certain time</p>
<pre><code class="language-javascript">function sayHello (){
    console.log(&quot;hello&quot;);
}

//you need a function and the time that you want things to happen, the time should be inputted in milliseconds so 5000 milliseconds = 5 seconds
setInterval(sayHello, 5000);</code></pre>
<h4 id="51-timeouts-and-dates">#5.1 (Timeouts and Dates)</h4>
<p>interval : repeat after a certain amount of time 
(ex. console.log every 5 seconds)
timeout : certain event once at a certain amount of time
(ex. console.log once after 5 seconds)</p>
<pre><code class="language-javascript">function sayHello (){
    console.log(&quot;hello&quot;);
}

setTimeout(sayHello, 5000);</code></pre>
<p>javascript code to make a clock</p>
<pre><code class="language-javascript">const clock = document.querySelector(&quot;h2#clock&quot;);

function getClock (){
    const date = new Date();
    clock.innerText =(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)
}

//we immediately call the function when we first open the window
getClock ()
//and it keeps going
setInterval(getClock, 1000);</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/520c99e1-a2b6-4462-b689-bfab109f0741/image.png" alt=""></p>
<h4 id="52-padstart">#5.2 (PadStart)</h4>
<p>however the second is displayed as 1,2,3 not 01, 02, 03 because they are just getting seconds from 0 to 59, so we need to format the seconds to look like 01,02,03</p>
<pre><code class="language-javascript">//if we have a string that is 1 string long which is &quot;1&quot;, then we make it two characters long, and we add 0 infront of them (because it is padStart, we also have padEnd, that puts the certain character in the end), then the output of the following code will be &quot;01&quot;
&quot;1&quot;.padStart(2,&quot;0&quot;)</code></pre>
<p>another example of padStart would be
<img src="https://velog.velcdn.com/images/jisu_lee/post/a155bd25-6273-4005-99db-1d5423416033/image.png" alt=""></p>
<p>the final javascript code using padStart</p>
<pre><code class="language-javascript">const clock = document.querySelector(&quot;h2#clock&quot;);

function getClock (){
    const date = new Date();
  //we get numbers so we want them to be converted to strings
    const hours = String(date.getHours()).padStart(2,&quot;0&quot;);
    const minutes = String(date.getMinutes()).padStart(2,&quot;0&quot;);
    const seconds = String(date.getSeconds()).padStart(2,&quot;0&quot;);
    clock.innerText =(`${hours}:${minutes}:${seconds}`)
}

//we immediately call the function when we first open the window
getClock ()
//and it keeps going, we want to call the function every second over and over again so we are using the interval
setInterval(getClock, 1000);</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/6413f98b-b647-4158-8062-312d3325a5ef/image.png" alt=""></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Python Project #1]]></title>
            <link>https://velog.io/@jisu_lee/Python-Project-1-nor99k2z</link>
            <guid>https://velog.io/@jisu_lee/Python-Project-1-nor99k2z</guid>
            <pubDate>Wed, 22 Feb 2023 13:19:06 GMT</pubDate>
            <description><![CDATA[<p>야구장 좌석 추천 및 승률 계산 Python 프로젝트
<img src="https://velog.velcdn.com/images/jisu_lee/post/1729b58d-ab31-4963-83ea-25c3af560155/image.png" alt=""></p>
<pre><code class="language-python">#
# 야구장 좌석 추천 및 승률 계산 Python 프로젝트
#
print (&quot;이 프로그램은 야구 관람이 서툰 분들을 위해 제작되었습니다.&quot;)
print (&quot;여러분들에게 가장 적합한 좌석을 추천해드리며, 여러분들이 응원하는 팀이 승리할 확률을 구해줍니다.&quot;)

print (&quot;먼저, 여러분들에게 가장 적합한 좌석을 추천해드리겠습니다.&quot;)


stadium_list = ( \
    (1,&#39;잠실 야구장(두산)&#39;), \
    (2,&#39;잠실 야구장(엘지)&#39;), \
    (3,&#39;부산 사직 야구장&#39;), \
    (4,&#39;인천 SK 행복 드림 구장&#39;), \
    (5,&#39;창원 NC 파크&#39;), \
    (6,&#39;광주 챔피언스 필드&#39;), \
    (7,&#39;고척 스카이돔&#39;), \
    (8,&#39;삼성 라이온즈 파크&#39;), \
    (9,&#39;한화 생명 이글스 파크&#39;), \
    (10,&#39;수원 KT 위즈 파크&#39;) \
    )

seat_q_list = ( \
    (1, &quot;당신은 치어리더와 함께 응원 열기를 즐기면서 경기를 관람하고 싶나요?&quot;, 6,5,2,4,1,3 ), \
    (2, &quot;당신은 넓은 시야에서 전체적으로 야구 경기를 관람하고 싶나요?&quot;, 2,3,6,1,5,4 ), \
    (3, &quot;내야 수비진과 투수진들을 가까이에서 보고 싶나요?&quot;, 4,6,2,5,1,3), \
    (4, &quot;편하게 음식을 먹으면서 경기를 관람하고 싶나요?&quot;, 1,4,4,2,4,6), \
    (5, &quot;직접 선수들과 함께 경기를 뛰는 느낌을 체험하고 싶나요?&quot;, 5,4,2,6,3,1), \
    (6, &quot;외야 수비진들을 가까이에서 보고 싶나요?&quot;, 3,5,1,2,6,4) \
    )

#
# 구장 선택
#
for stad_id, stad_name in stadium_list :
    print(f&#39;({stad_id}) {stad_name}&#39;)

ans = input (&quot;오늘 방문하는 구장이 어디인가요 (1~10)?&quot;)
print(ans)

#
# 선택한 구장 출력
#
for stad_id, stad_name in stadium_list :
    # print(f&#39;{ans} {stad_id} {stad_name}&#39;)
    if str(ans) == str(stad_id) :
        print(f&#39;{stad_name}&#39;)
        break
# stad_id
# stad_name

#
# 선호 좌석 유형 질문
#
cheer = 0.1
ilban = 0.2
center = 0.3
exciting = 0.4
outside = 0.5
table = 0.6

for q_id, q_seat, s1,s2,s3,s4,s5,s6 in seat_q_list :
    print(q_seat, end=&#39;(y/n)&#39;)
    ans = input(&#39;: &#39;)
    if str(ans) == &#39;y&#39; :
        cheer = cheer + s1
        ilban = ilban + s2
        center = center + s3
        exciting = exciting + s4
        outside = outside + s5
        table = table + s6
    elif str(ans) == &#39;n&#39; :
        cheer = cheer - s1
        ilban = ilban - s2
        center = center - s3
        exciting = exciting - s4
        outside = outside - s5
        table = table - s6

#
# 각 구장마다 좌석이름
#
seat_name_list = ( \
    (1, &quot;레드석&quot;, &quot;블루석&quot;, &quot;중앙네이비석&quot;, &quot;익사이팅존&quot;, &quot;외야자유석&quot;, &quot;테이블석&quot;), \
    (2, &quot;레드석&quot;, &quot;블루석&quot;, &quot;중앙네이비석&quot;, &quot;익사이팅존&quot;, &quot;외야자유석&quot;, &quot;테이블석&quot;), \
    (3, &quot;내야필드석&quot;, &quot;내야상단석&quot; , &quot;중앙상단석&quot;, &quot;익사이팅존&quot;, &quot;외야자유석&quot;, &quot;탁자석&quot;), \
    (4, &quot;응원지정석&quot;, &quot;의자지정석&quot; , &quot;중앙일반석&quot;, &quot;프렌들리존&quot;, &quot;외야일반석&amp;그린존&quot;, &quot;탁자지정석&quot;), \
    (5, &quot;응원석&quot;, &quot;내야지정석&quot; , &quot;필드,중앙테이블&quot;, &quot;다이나믹존&quot;, &quot;외야지정석&quot;, &quot;테이블석&quot;), \
    (6, &quot;K5&quot;, &quot;K7&quot; , &quot;중앙K3&quot;, &quot;서프라이즈석&quot;, &quot;외야석&quot;, &quot;피크닉석,페이코석&quot;), \
    (7, &quot;버건디석&quot;, &quot;다크버건디석&quot; , &quot;중앙지정석&quot;, &quot;로얄다이아몬드클럽&quot;, &quot;외야(비)지정석&quot;, &quot;테이블석&quot;), \
    (8, &quot;블루존&quot;, &quot;내야지정석&quot; , &quot;중앙스카이지정석&quot;, &quot;익사이팅석&quot;, &quot;외야석&quot;, &quot;테이블석&quot;), \
    (9, &quot;내야응원단석&quot;, &quot;내야지정석&quot; , &quot;한화다이렉트,페이코존&quot;, &quot;익사이팅존&quot;, &quot;외야지정석&quot;, &quot;탁자석&quot;), \
    (10, &quot;내야지정석(응원석)&quot;, &quot;내야지정석(일반관람석)&quot; , &quot;스카이존&quot;, &quot;익사이팅석&quot;, &quot;외야자유석&quot;, &quot;테이블석&quot;) \
    )

for stad_i, cheer_seat, ilban_seat, center_seat, exciting_seat, outside_seat, table_seat in seat_name_list :
    if stad_id == stad_i :
        break

#
# key 값이 동일하면 앞에 정의한 것이 지워져서
# 제일 처음 각 변수의 초기값을 소숫점에서 다르게 정했음.
#
dlist = { \
    cheer : cheer_seat, \
    ilban : ilban_seat, \
    center : center_seat, \
    exciting : exciting_seat, \
    outside : outside_seat, \
    table : table_seat \
    }    
dlist.keys()
dlist_keys = list(dlist.keys())
dlist_keys.sort(reverse=True)

print(&quot;당신에게 가장 적합한 좌석은 다음 순서와 같습니다. : \n&quot;, list(dlist.values()))

#
# 응원팀 승리확률(보너스)
#

import random

print(&#39;\n이번에는랜덤으로 질문을 뽑아 오늘 당신이 응원하는 팀이 승리할 확률을 구해드리겠습니다. y 또는 n로 대답해주세요.\n&#39;)

team = input (&quot;당신이 가장 응원하는 팀은 어디인가요?&quot;)

q_all_list = ( \
    (f&#39;{team}의 상대팀에 대한 승률이 6할 이상입니까?&#39;,&#39;y&#39;,30,&#39;n&#39;,5), \
    (f&#39;{team}의 선발투수가 지난 시즌 10승 이상을 기록하고 있습니까?&#39;,&#39;y&#39;,30,&#39;n&#39;,5), \
    (f&#39;{team}의 4번 타자 시즌 장타율이 5할 이상입니까?&#39;,&#39;y&#39;,20,&#39;n&#39;,5), \
    (f&#39;{team}의 9번 타자 시즌 타율이 2할 이상입니까?&#39;,&#39;y&#39;,30,&#39;n&#39;,10), \
    (f&#39;{team}의 1번타자의 시즌 출루율이 3할 6푼 이상입니까?&#39;,&#39;y&#39;,40,&#39;n&#39;,5), \
    (f&#39;{team}의 포수의 시즌 도루저지율이 2할 5푼 이상입니까?&#39;,&#39;y&#39;,60,&#39;n&#39;,10), \
    (f&#39;{team}의 외야수 세 명의 수비율이 모두 9할 8푼 이상입니까?&#39;,&#39;y&#39;,5,&#39;n&#39;,0), \
    (f&#39;{team}의 내야수 네 명의 수비율이 모두 9할 5푼 이상입니까?&#39;,&#39;y&#39;,30,&#39;n&#39;,5), \
    (f&#39;{team}의 선발투수의 평균자책점이 3점 이하입니까?&#39;,&#39;y&#39;,20,&#39;n&#39;,10), \
    (f&#39;{team}의 선발투수 시즌 승률/ 지난 시즌 승률이 7할 5푼 이상입니까?&#39;,&#39;y&#39;,50,&#39;n&#39;,10), \
    (f&#39;{team}의 선발투수의 지난 시즌 WAR이 3.5 이상입니까?&#39;,&#39;y&#39;,40,&#39;n&#39;,20), \
    (f&#39;{team}의 5회까지 팀 실책이 하나 이상입니까?&#39;,&#39;y&#39;,40,&#39;n&#39;,10), \
    (f&#39;{team}의 안타율이 지난 시즌 평균 이상입니까?&#39;,&#39;y&#39;,30,&#39;n&#39;,10), \
    (f&#39;{team}의 장타율이 지난 시즌 평균 이상입니까?&#39;,&#39;y&#39;,50,&#39;n&#39;,10), \
    (f&#39;{team}의 중간 계투진의 피안타율이 모두 2할 이하입니까?&#39;,&#39;y&#39;,20,&#39;n&#39;,5), \
    (f&#39;{team}의 중간 계투진의 평균 자책점이 모두 5.5점 이하입니까?&#39;,&#39;y&#39;,20,&#39;n&#39;,5), \
    (f&#39;{team}의 2번 타자의 OPS가 8할 5푼 이상입니까?&#39;,&#39;y&#39;,50,&#39;n&#39;,10), \
    (f&#39;{team}의 3번 타자의 OPS가 8할 5푼 이상입니까?&#39;,&#39;y&#39;,30,&#39;n&#39;,0), \
    (f&#39;{team}의 4번 타자의 지난 시즌 홈런 개수가 20개 이상입니까?&#39;,&#39;y&#39;,40,&#39;n&#39;,20), \
    (f&#39;{team}의 지명타자의 지난 시즌 안타 개수가 160개 이상입니까?&#39;,&#39;y&#39;,20,&#39;n&#39;,5), \
    )
q_list = random.sample(q_all_list, 12)




total_score = 0
my_score = 0
for q, a, w, a2, w2 in q_list :
    q_colon = q + &#39; : &#39;
    my_ans = input(q_colon)
    if w &lt; w2 :
        total_score = total_score + w2
    else :
        total_score = total_score + w
    if my_ans == a :
        my_score = my_score + w
    elif my_ans == a2 :
        my_score = my_score + w2
print(&#39;Total score = &#39;, total_score)
print(&#39;My score = &#39;, my_score)
percentage = round(my_score * 100)/total_score
print(f&#39;오늘 {team}이/가 승리할 확률은 &#39;,percentage,&#39;입니다&#39;)</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[Javascript Day3]]></title>
            <link>https://velog.io/@jisu_lee/Javascript-Day3</link>
            <guid>https://velog.io/@jisu_lee/Javascript-Day3</guid>
            <pubDate>Sun, 19 Feb 2023 12:42:34 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/jisu_lee/post/02f49c5d-e43b-496c-bd66-7b06ff5ed3d7/image.png" alt=""></p>
<p>오늘은 nomadcoders 강의를 통한 javascript 공부 세 번째 날입니다.</p>
<h4 id="40-input-values">#4.0 (Input Values)</h4>
<p>html (make input and a button)</p>
<pre><code class="language-html">&lt;body&gt;
&lt;div id=&quot;login-form&quot;&gt;
&lt;input type=&quot;text&quot; placeholder=&quot;What is your name?&quot;/&gt;
&lt;button&gt;Log In&lt;/button&gt;
&lt;/div&gt;
  &lt;script src=&quot;app.js&quot;&gt;&lt;/script&gt;   
&lt;/body&gt;</code></pre>
<p>javascript (get the input and the button)</p>
<pre><code class="language-javascript">//search for the id
const loginForm=document.getElementById(&quot;login-form&quot;);
//inside of the id-form we search for the input and the button
const loginInput=loginForm.querySelector(&quot;input&quot;);
const loginButton=loginForm.querySelector(&quot;button&quot;);
//the same thing is
const loginInput2=document.querySelector(&quot;#login-form input&quot;);
const loginButton2=document.querySelector(&quot;#login-form button&quot;);</code></pre>
<p>display &quot;clicked&quot; when the login button is clicked</p>
<pre><code class="language-javascript">//search for the id
const loginForm=document.getElementById(&quot;login-form&quot;);
//inside of the id-form we search for the input and the button
const loginInput=loginForm.querySelector(&quot;input&quot;);
const loginButton=loginForm.querySelector(&quot;button&quot;);


function onLoginBtnClick() {
    console.log(&quot;clicked&quot;)
}
loginButton.addEventListener(&quot;click&quot;,onLoginBtnClick);</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/485f78e9-9933-49d9-8561-aa4cb0081502/image.png" alt=""></p>
<p>get the value when pressed the button</p>
<pre><code class="language-javascript">//search for the id
const loginForm=document.getElementById(&quot;login-form&quot;);
//inside of the id-form we search for the input and the button
const loginInput=loginForm.querySelector(&quot;input&quot;);
const loginButton=loginForm.querySelector(&quot;button&quot;);


function onLoginBtnClick() {
    console.log(loginInput.value)
    }
loginButton.addEventListener(&quot;click&quot;,onLoginBtnClick);</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/d5ca8878-27da-4139-a1f6-6a8a1f596fc8/image.png" alt=""></p>
<h4 id="41-form-submission">#4.1 (Form Submission)</h4>
<p>using if statement for conditionals (alert when the value is empty or too long)</p>
<pre><code class="language-javascript">//search for the id
const loginForm=document.getElementById(&quot;login-form&quot;);
//inside of the id-form we search for the input and the button
const loginInput=loginForm.querySelector(&quot;input&quot;);
const loginButton=loginForm.querySelector(&quot;button&quot;);

function onLoginBtnClick() {
    const username=loginInput.value;
    if (username===&quot;&quot;){
        alert(&quot;Please write your name&quot;);
    }else if(username.length&gt;15){
        alert(&quot;Your name is too long&quot;);
    }
    }
loginButton.addEventListener(&quot;click&quot;,onLoginBtnClick);</code></pre>
<p>can set conditionals with html</p>
<pre><code class="language-html">&lt;body&gt;
&lt;form id=&quot;login-form&quot;&gt;
&lt;input 
   required
   maxlength=&quot;15&quot;
   type=&quot;text&quot; 
   placeholder=&quot;What is your name?&quot;/&gt;
&lt;button&gt;Log In&lt;/button&gt;

  &lt;script src=&quot;app.js&quot;&gt;&lt;/script&gt;   
&lt;/body&gt;</code></pre>
<p>however everytime I press login button or press enter, the form will be submitted and the page will be refreshed -&gt; we don&#39;t get to focus on clicking the button anymore and all we care is about submitting the form (value)</p>
<h4 id="4243-events">#4.2~4.3 (Events)</h4>
<p>we don&#39;t need the button anymore as we are focusing on the submit action</p>
<pre><code class="language-javascript">//search for the id
const loginForm=document.getElementById(&quot;login-form&quot;);
//inside of the id-form we search for the input and the button
const loginInput=loginForm.querySelector(&quot;input&quot;);


function onLoginSubmit() {
    const username=loginInput.value;
    console.log(username);
    }

loginForm.addEventListener(&quot;submit&quot;,onLoginSubmit);</code></pre>
<p>stopping the page refresh from happening</p>
<pre><code class="language-javascript">//search for the id
const loginForm=document.getElementById(&quot;login-form&quot;);
//inside of the id-form we search for the input and the button
const loginInput=loginForm.querySelector(&quot;input&quot;);


function onLoginSubmit(event) {
      //stops the default behavior of the window such as refreshing the page
    event.preventDefault();
    console.log(loginInput.value);
    }

loginForm.addEventListener(&quot;submit&quot;,onLoginSubmit);</code></pre>
<p>you are creating a function (onLoginSubmit) and giving that function one argument (event), when somebody submits the form, javascript will call the function with the event object, and the object has the function called preventDefault which will stop the default behaviors from happening</p>
<p>preventDefault 함수는 EventListener 함수의 &#39;첫 번째 argument&#39; 안에 있는 함수인데, 첫 argument는 지금 막 벌어진 event들에 대한 정보를 갖고 있다. JS는(기본적으로)argument를 담아서 함수를 호출하는데, 이 argument가 기본 정보들을 제공하고 있다. ex) 누가 submit주체인지, 몇 시에 submit을 했는지 등등 콘솔에 출력해보면 알 수 있음</p>
<p>another example with clicking link and moving on to a new website</p>
<pre><code class="language-html">&lt;body&gt;
&lt;form id=&quot;login-form&quot;&gt; &lt;/form&gt;
&lt;a href=&quot;https://nomadcoders.com&quot;&gt;Go to courses&lt;/a&gt;
&lt;script src=&quot;app.js&quot;&gt;&lt;/script&gt;   
&lt;/body&gt;</code></pre>
<p>javascript to set alert when the link is clicked (however does move on to the website when the alert is closed - default)</p>
<pre><code class="language-javascript">const link=document.querySelector(&quot;a&quot;);

function handleLinkClick(){
    alert(&quot;clicked&quot;);
}

link.addEventListener(&quot;click&quot;,handleLinkClick);</code></pre>
<p>more about the object in the function</p>
<pre><code class="language-javascript">//search for the id
const loginForm=document.getElementById(&quot;login-form&quot;);
//inside of the id-form we search for the input and the button
const loginInput=loginForm.querySelector(&quot;input&quot;);

function onLoginSubmit(event) {
    event.preventDefault();
    console.log(loginInput.value);
    }

loginForm.addEventListener(&quot;submit&quot;,onLoginSubmit);

const link=document.querySelector(&quot;a&quot;);

function handleLinkClick(event){
    console.log(event);
    alert(&quot;clicked&quot;);
}

link.addEventListener(&quot;click&quot;,handleLinkClick);

//the first object(event) in the function(handleLinkClick) will the be information about the event(link being click) that just happened
//when console.log(event), there are many information that I can get, because it is a &quot;click&quot;, this event is regarded as a pointerevent</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/4bbd0424-75e7-4cb0-bb35-4823e0e89c4e/image.png" alt="">
the browser will not lead us to the new website because we prevented the default action</p>
<pre><code class="language-javascript">onst link=document.querySelector(&quot;a&quot;);

function handleLinkClick(event){
    event.preventDefault();
}

link.addEventListener(&quot;click&quot;,handleLinkClick);</code></pre>
<h4 id="44-getting-username">#4.4 (Getting Username)</h4>
<p>step 1 (the user submits the username and the form disappears)
html script</p>
<pre><code class="language-html">&lt;body&gt;
   &lt;form id=&quot;login-form&quot;&gt;
   &lt;input 
      required
      maxlength=&quot;15&quot;
      type=&quot;text&quot; 
      placeholder=&quot;What is your name?&quot;/&gt;
   &lt;input type=&quot;submit&quot; value=&quot;Log In&quot;/&gt;
   &lt;/form&gt;
   &lt;script src=&quot;app.js&quot;&gt;&lt;/script&gt;   
   &lt;/body&gt;</code></pre>
<p>css script (make a class called hidden)</p>
<pre><code class="language-css">.hidden{
    display:none;
}</code></pre>
<p>javascript (css is triggered when the user inputs their username)</p>
<pre><code class="language-javascript">//search for the id
const loginForm=document.getElementById(&quot;login-form&quot;);
//inside of the id-form we search for the input and the button
const loginInput=loginForm.querySelector(&quot;input&quot;);

function onLoginSubmit(event) {
    event.preventDefault();
    const username=loginInput.value;
    loginForm.classList.add(&quot;hidden&quot;);
    console.log(username);
    }

loginForm.addEventListener(&quot;submit&quot;,onLoginSubmit);</code></pre>
<p>step 2 (make the username appear)
html script (add ID called &quot;greeting&quot;)</p>
<pre><code class="language-html">&lt;body&gt;
   &lt;form id=&quot;login-form&quot;&gt;
   &lt;input 
      required
      maxlength=&quot;15&quot;
      type=&quot;text&quot; 
      placeholder=&quot;What is your name?&quot;/&gt;
   &lt;input type=&quot;submit&quot; value=&quot;Log In&quot;/&gt;
   &lt;/form&gt;
   &lt;h1 id=&quot;greeting&quot; class=&quot;hidden&quot;&gt;&lt;/h1&gt;
   &lt;script src=&quot;app.js&quot;&gt;&lt;/script&gt;   
   &lt;/body&gt;</code></pre>
<p>javascript</p>
<pre><code class="language-javascript">//search for the id
const loginForm=document.getElementById(&quot;login-form&quot;);
//inside of the id-form we search for the input and the button
const loginInput=loginForm.querySelector(&quot;input&quot;);
//grabbing the id from the html script
const greeting = document.querySelector(&quot;#greeting&quot;);

//uppercase variables are variables that are regarded to contain only strings
const HIDDEN_CLASSNAME = &quot;hidden&quot;;

function onLoginSubmit(event) {
    //prevent the default event from happening
    event.preventDefault();
    //hide the form by adding the hidden classname
    loginForm.classList.add(HIDDEN_CLASSNAME);
    //save the username in a variable
    const username=loginInput.value;
     //put some text inside the h1(greeting)
    greeting.innerText = &quot;Hello &quot; + username;
      //h1 has the text but we need to remove the hidden class
    greeting.classList.remove(HIDDEN_CLASSNAME);
    }

loginForm.addEventListener(&quot;submit&quot;,onLoginSubmit);</code></pre>
<p>displaying the username with different code (&#39;는 숫자 1옆에 있는 물결표시와 함께 사용되는 자판을 이용할 것)</p>
<pre><code class="language-javascript">//search for the id
const loginForm=document.getElementById(&quot;login-form&quot;);
//inside of the id-form we search for the input and the button
const loginInput=loginForm.querySelector(&quot;input&quot;);

const greeting = document.querySelector(&quot;#greeting&quot;);

//uppercase variables are variables that are regarded to contain only strings
const HIDDEN_CLASSNAME = &quot;hidden&quot;;

function onLoginSubmit(event) {
    //prevent the default event from happening
    event.preventDefault();
    //hide the form by adding the hidden classname
    loginForm.classList.add(HIDDEN_CLASSNAME);
    //save the username in a variable
    const username=loginInput.value;
    greeting.innerText = `Hello ${username} keep writing`;
    greeting.classList.remove(HIDDEN_CLASSNAME);
    }

loginForm.addEventListener(&quot;submit&quot;,onLoginSubmit);</code></pre>
<h4 id="45-saving-username">#4.5 (Saving Username)</h4>
<p>there is an API (local storage) that has the program to remember values in the browser -&gt; go to developer tools -&gt; application and you can find the local storage</p>
<p>the first one is regarded as key and the second is regarded as value</p>
<pre><code class="language-javascript">localStorage.setItem(&quot;username&quot;,&quot;jisu&quot;)</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/38853fa1-2e4c-4fdf-bbea-6392dac5f7f9/image.png" alt="">
get the value</p>
<pre><code class="language-javascript">localStorage.getItem(&quot;username&quot;)</code></pre>
<p>remove the value</p>
<pre><code class="language-javascript">localStorage.removeItem(&quot;username&quot;)</code></pre>
<p>javascript to save the value</p>
<pre><code class="language-javascript">//search for the id
const loginForm=document.getElementById(&quot;login-form&quot;);
//inside of the id-form we search for the input and the button
const loginInput=loginForm.querySelector(&quot;input&quot;);

const greeting = document.querySelector(&quot;#greeting&quot;);

//uppercase variables are variables that are regarded to contain only strings
const HIDDEN_CLASSNAME = &quot;hidden&quot;;

function onLoginSubmit(event) {
    //prevent the default event from happening
    event.preventDefault();
    //hide the form by adding the hidden classname
    loginForm.classList.add(HIDDEN_CLASSNAME);
    //save the username in a variable
    const username=loginInput.value;
      //save the value in the local storage
    localStorage.setItem(&quot;username&quot;,username);
    //we take the empty h1 and fill it with username
    greeting.innerText = `Hello ${username} keep writing`;
    //remove the clasname named &quot;hidden&quot;
    greeting.classList.remove(HIDDEN_CLASSNAME);
    }

loginForm.addEventListener(&quot;submit&quot;,onLoginSubmit);</code></pre>
<h4 id="46loading-username">#4.6(Loading Username)</h4>
<p>check if the user already exists in the local storage
when there is no username in the local storgae, the following code displays &quot;null&quot;</p>
<pre><code class="language-javascript">localStorage.getItem(&quot;username&quot;)</code></pre>
<p>add a &quot;hidden&quot; class to the form so the browser displays nothing at first</p>
<pre><code class="language-html">&lt;body&gt;
   &lt;form class=&quot;hidden&quot; id=&quot;login-form&quot;&gt;
   &lt;input 
      required
      maxlength=&quot;15&quot;
      type=&quot;text&quot; 
      placeholder=&quot;What is your name?&quot;/&gt;
   &lt;input type=&quot;submit&quot; value=&quot;Log In&quot;/&gt;
   &lt;/form&gt;
   &lt;h1 id=&quot;greeting&quot; class=&quot;hidden&quot;&gt;&lt;/h1&gt;
   &lt;script src=&quot;app.js&quot;&gt;&lt;/script&gt;   
   &lt;/body&gt;</code></pre>
<p>if statement --&gt; when the local storage is null, then the hidden class in the form is removed and the login form is displayed (onLoginSubmit function is executed), once it is saved then afterwards the browser keeps displaying &quot;hello username&quot;</p>
<pre><code class="language-javascript">//search for the id
const loginForm=document.getElementById(&quot;login-form&quot;);
//inside of the id-form we search for the input and the button
const loginInput=loginForm.querySelector(&quot;input&quot;);

const greeting = document.querySelector(&quot;#greeting&quot;);

//uppercase variables are variables that are regarded to contain only strings
const HIDDEN_CLASSNAME = &quot;hidden&quot;;
//when you are repeating strings, it is better to save them as constant variables 
const USERNAME_KEY = &quot;username&quot;;

function onLoginSubmit(event) {
    //prevent the default event from happening
    event.preventDefault();
    //hide the form by adding the hidden classname
    loginForm.classList.add(HIDDEN_CLASSNAME);
    //save the username in a variable
    const username=loginInput.value;
    localStorage.setItem(USERNAME_KEY,username);
    //we take the empty h1 and fill it with username
    greeting.innerText = `Hello ${username}`;
    //remove the clasname named &quot;hidden&quot;
    greeting.classList.remove(HIDDEN_CLASSNAME);
    }

const savedUsername=localStorage.getItem(USERNAME_KEY);
if (savedUsername===null){
    //show the form
    loginForm.classList.remove(HIDDEN_CLASSNAME);
    loginForm.addEventListener(&quot;submit&quot;,onLoginSubmit);
}else{
    //show the greeting comments
    greeting.innerText = `Hello ${savedUsername}`;
    greeting.classList.remove(HIDDEN_CLASSNAME);
}</code></pre>
<p>removing the same lines of code with a function called &quot;paintGreetings&quot;</p>
<pre><code class="language-javascript">//search for the id
const loginForm=document.getElementById(&quot;login-form&quot;);
//inside of the id-form we search for the input and the button
const loginInput=loginForm.querySelector(&quot;input&quot;);

const greeting = document.querySelector(&quot;#greeting&quot;);

//uppercase variables are variables that are regarded to contain only strings
const HIDDEN_CLASSNAME = &quot;hidden&quot;;
//when you are repeating strings, it is better to save them as constant variables 
const USERNAME_KEY = &quot;username&quot;;

function onLoginSubmit(event) {
    //prevent the default event from happening
    event.preventDefault();
    //hide the form by adding the hidden classname
    loginForm.classList.add(HIDDEN_CLASSNAME);
    //save the username in a variable
    const username=loginInput.value;
    localStorage.setItem(USERNAME_KEY,username);
      //the username is coming from the loginInput.value
    paintGreetings(username);
    }

function paintGreetings(username){
    greeting.innerText = `Hello ${username}`;
    greeting.classList.remove(HIDDEN_CLASSNAME);
}

const savedUsername=localStorage.getItem(USERNAME_KEY);
if (savedUsername===null){
    //show the form
    loginForm.classList.remove(HIDDEN_CLASSNAME);
    loginForm.addEventListener(&quot;submit&quot;,onLoginSubmit);
}else{
    //show the greeting comments
      //the username is comming from the local storage
    paintGreetings(savedUsername);
}</code></pre>
<p>paintGreetings() really don&#39;t have to receive anything, because we know there is a user in the local storage, however this way we search for the username two times with the code (localStorage.getItem(USERNAME_KEY);)</p>
<pre><code class="language-javascript">//search for the id
const loginForm=document.getElementById(&quot;login-form&quot;);
//inside of the id-form we search for the input and the button
const loginInput=loginForm.querySelector(&quot;input&quot;);

const greeting = document.querySelector(&quot;#greeting&quot;);

//uppercase variables are variables that are regarded to contain only strings
const HIDDEN_CLASSNAME = &quot;hidden&quot;;
//when you are repeating strings, it is better to save them as constant variables 
const USERNAME_KEY = &quot;username&quot;;

function onLoginSubmit(event) {
    //prevent the default event from happening
    event.preventDefault();
    //hide the form by adding the hidden classname
    loginForm.classList.add(HIDDEN_CLASSNAME);
    //save something on the local storage
    localStorage.setItem(USERNAME_KEY,username);
    //the moment we call the function, that username will already be saved on the local storage
    paintGreetings();
    }

function paintGreetings(){
      //look for the username in the local storage
    const username= localStorage.getItem(USERNAME_KEY);
    greeting.innerText = `Hello ${username}`;
    greeting.classList.remove(HIDDEN_CLASSNAME);
}

const savedUsername=localStorage.getItem(USERNAME_KEY);
if (savedUsername===null){
    //show the form
    loginForm.classList.remove(HIDDEN_CLASSNAME);
    loginForm.addEventListener(&quot;submit&quot;,onLoginSubmit);
}else{
    //show the greeting comments
    paintGreetings();
}</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[Javascript Day2]]></title>
            <link>https://velog.io/@jisu_lee/Javascript-Day2</link>
            <guid>https://velog.io/@jisu_lee/Javascript-Day2</guid>
            <pubDate>Thu, 09 Feb 2023 12:23:16 GMT</pubDate>
            <description><![CDATA[<p>Javascript 스터디 두번째 시간입니다. 오늘은 nomadcoders 강의를 3강까지 들었습니다. 벌써 50%나 완료했네용. </p>
<p><img src="https://velog.velcdn.com/images/jisu_lee/post/fe997fe3-7bbb-42fa-be15-6498086706ce/image.png" alt=""></p>
<h4 id="30-the-document-object">#3.0 (The Document Object)</h4>
<blockquote>
<p>• when you type &#39;document&#39; in the console, it displays the html script, this means that &#39;document&#39; is an object already built in the browser
• document.title : you can get the title written in the html script </p>
</blockquote>
<pre><code class="language-javascript">&lt;title&gt; Title &lt;/title&gt;</code></pre>
<p>• when you type document.title=&quot;Hi&quot;, then the title changes to &#39;Title&#39;
• you are able to read html from javacript, but you are also able to change html in javacript (refresh? then changed to the original value)</p>
<h4 id="31-html-in-javascript">#3.1 (HTML in Javascript)</h4>
<p>add a new line in html script</p>
<pre><code class="language-html">&lt;body&gt;
 &lt;h1 id=&quot;title&quot;&gt;Grab me!&lt;/h1&gt;
 &lt;script src=&quot;app.js&quot;&gt;&lt;/script&gt;   
&lt;/body&gt;</code></pre>
<p>to see the data of the object &#39;title&#39;</p>
<pre><code class="language-javascript">const title = document.getElementById(&quot;title&quot;);
console.dir(title);</code></pre>
<p>change and check html using javascript</p>
<pre><code class="language-javascript">//we&#39;ve created an element in the html which is
&lt;h1 class=&quot;hello&quot; id=&quot;title&quot;&gt;Grab me!&lt;/h1&gt;
//grabbed it here
const title = document.getElementById(&quot;title&quot;);
//changed the name of the title
title.innerText=&quot;Got you&quot;;
//you can check the id 
console.log(title.id);
//you can check the class
console.log(title.className);</code></pre>
<h4 id="32-searching-for-elements">#3.2 (Searching for Elements)</h4>
<p>html code with 5 lines of h1</p>
<pre><code class="language-html">&lt;body&gt;
 &lt;h1 class=&quot;title&quot;&gt;Grab me!&lt;/h1&gt;
 &lt;h1 class=&quot;title&quot;&gt;Grab me!&lt;/h1&gt;
 &lt;h1 class=&quot;title&quot;&gt;Grab me!&lt;/h1&gt;
 &lt;h1 class=&quot;title&quot;&gt;Grab me!&lt;/h1&gt;
 &lt;h1 class=&quot;title&quot;&gt;Grab me!&lt;/h1&gt;
 &lt;script src=&quot;app.js&quot;&gt;&lt;/script&gt;   
&lt;/body&gt;</code></pre>
<p>javascript code to display them</p>
<pre><code class="language-javascript">const hellos = document.getElementsByClassName(&quot;hello&quot;);

console.log(hellos);

//hellos is an array so it doesn&#39;t have hellos.something
//it is get Element&#39;s&#39;, be careful of the s</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/5d48d699-e3b5-419d-a658-5d745a3733b9/image.png" alt=""></p>
<p>you try something new by changing the html code using div</p>
<pre><code class="language-html">&lt;body&gt;
 &lt;div class=&quot;hello&quot;&gt;
    &lt;h1&gt;Grab me!&lt;/h1&gt;
 &lt;/div&gt;
 &lt;script src=&quot;app.js&quot;&gt;&lt;/script&gt;   
&lt;/body&gt;</code></pre>
<p>getElementsByTagName in javascript</p>
<pre><code class="language-javascript">const title = document.getElementsByTagName(&quot;h1&quot;);
console.log(title);
//still title is an array, it can&#39;t do title.something</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/17d069a8-0d42-4ce8-ada0-373f3d09f5ac/image.png" alt=""></p>
<p>document.querySelector (grab something using the css selector)</p>
<pre><code class="language-javascript">const title = document.querySelector(&quot;.hello h1&quot;);
console.log(title);
//inside the class &quot;hello&quot; get me the h1
//.hello because it is a css selector</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/7736025e-78cd-4314-91a3-f9d6b5d6e602/image.png" alt=""></p>
<p>you only get the first element when using document.querySelector even though you repeat it in the html script</p>
<pre><code class="language-html">&lt;body&gt;
 &lt;div class=&quot;hello&quot;&gt;
    &lt;h1&gt;Grab me1&lt;/h1&gt;
 &lt;/div&gt;
 &lt;div class=&quot;hello&quot;&gt;
    &lt;h1&gt;Grab me2&lt;/h1&gt;
 &lt;/div&gt;
 &lt;div class=&quot;hello&quot;&gt;
    &lt;h1&gt;Grab me3&lt;/h1&gt;
 &lt;/div&gt;
 &lt;script src=&quot;app.js&quot;&gt;&lt;/script&gt;   
&lt;/body&gt;</code></pre>
<p>javascript with .querySelector</p>
<pre><code class="language-javascript">const title = document.querySelector(&quot;.hello h1&quot;);
console.log(title);</code></pre>
<p>the output is still 
<img src="https://velog.velcdn.com/images/jisu_lee/post/00d0d37a-cd20-4859-96bd-ee4ec5b4d51f/image.png" alt=""></p>
<p>change to querySelectorAll and it gives you an array of 3 h1</p>
<pre><code class="language-javascript">const title = document.querySelectorAll(&quot;.hello h1&quot;);
console.log(title);</code></pre>
<p>the output
<img src="https://velog.velcdn.com/images/jisu_lee/post/d16c0abe-532f-48c0-9e2a-58cf4d532200/image.png" alt=""></p>
<p>the two codes are the same thing</p>
<pre><code class="language-javascript">//in querySelector you don&#39;t know what you are searching for so you add # to indicate it is an ID
const title = document.querySelector(&quot;#hello&quot;);
const title = document.getElementById(&quot;hello&quot;);</code></pre>
<p>everything using javascript on html is possible because we have</p>
<pre><code class="language-html">&lt;script src=&quot;app.js&quot;&gt;&lt;/script&gt;</code></pre>
<h4 id="3335-events">#3.3~3.5 (Events)</h4>
<p>the following code will display &quot;Grab Me 1&quot;</p>
<pre><code class="language-javascript">const title = document.querySelector(&quot;div.hello:first-child h1&quot;);
console.log(title);</code></pre>
<p>change color</p>
<pre><code class="language-javascript">title.style.color=&quot;blue&quot;;</code></pre>
<p>event : when I click, when I press enter, when my mouse hovers over..</p>
<p>addEventListener(type, listener)
type: a case-sensitive string representing the event type to listen for
listener : the object that receives a notification (an object that implements the event interface) when an event of the specified type occures, this must be null, an object with a handleEvent() method, or a JavaScript function.</p>
<pre><code class="language-javascript">const title = document.querySelector(&quot;div.hello:first-child h1&quot;);

function handleTitleClick(){
    console.log(&quot;title was clicked&quot;);
}

title.addEventListener(&quot;click&quot;, handleTitleClick);
//javacript will look when someone clicks on the title and they will press play of the function for me
//so do not do handleTitleClick() because the javascript will play for us</code></pre>
<p>change the color whenever we press the sentence</p>
<pre><code class="language-javascript">const title = document.querySelector(&quot;div.hello:first-child h1&quot;);

function handleTitleClick(){
    title.style.color=&quot;blue&quot;;
}

title.addEventListener(&quot;click&quot;, handleTitleClick);</code></pre>
<p>to search for what events javascript can listen you can search for &quot;h1 html element mdn -web api&quot;
<a href="https://developer.mozilla.org/en-US/docs/Web/API/Element#events">click on the link and search for &quot;events&quot;</a></p>
<p>mouse hover over and displays comments</p>
<pre><code class="language-javascript">const title = document.querySelector(&quot;div.hello:first-child h1&quot;);
function handleMouseEnter(){
   console.log(&quot;mouse is here&quot;);
}
title.addEventListener(&quot;mouseenter&quot;, handleMouseEnter)</code></pre>
<p>when the mouse hovers then the text is changed, when the mouse is gone the text is also changed</p>
<pre><code class="language-javascript">const title = document.querySelector(&quot;div.hello:first-child h1&quot;);

function handleMouseEnter(){
    title.innerText=&quot;Mouse is here!&quot;;
}

function handleMouseLeave(){
    title.innerText=&quot;Mouse is gone!&quot;;
 }

title.addEventListener(&quot;mouseenter&quot;, handleMouseEnter)
title.addEventListener(&quot;mouseleave&quot;,handleMouseLeave)</code></pre>
<p>another way of listening to the events</p>
<pre><code class="language-javascript">title.addEventListener=(&quot;mouseenter&quot;, handleMouseEnter)
title.onmouseenter=handleMouseEnter
//they are the same
//the reason we use .addEventListener is that later we can do .removeEventListener</code></pre>
<p>resize window to change background color</p>
<pre><code class="language-javascript">function handleWindowResize(){
   document.body.style.backgroundColor=&quot;tomato&quot;;
}

window.addEventListener(&quot;resize&quot;,handleWindowResize)</code></pre>
<p>copy then show alert message</p>
<pre><code class="language-javascript">function handleWindowCopy(){
    alert(&quot;copier!&quot;);
 }
window.addEventListener(&quot;copy&quot;,handleWindowCopy)</code></pre>
<p>check wifi</p>
<pre><code class="language-javascript">function handleWindowOffline(){
    alert(&quot;SOS NO WIFI!&quot;);
 }
window.addEventListener(&quot;offline&quot;,handleWindowOffline)

function handleWindowOnline(){
    alert(&quot;WIFI CONNECTED!&quot;);
 }
window.addEventListener(&quot;online&quot;,handleWindowOnline)</code></pre>
<h4 id="3638-css-in-javascript">#3.6~3.8 (CSS in Javascript)</h4>
<p>get and set color</p>
<pre><code class="language-javascript">const h1 = document.querySelector(&quot;div.hello:first-child h1&quot;);

function handleTitleClick() {
    //get
    console.log(h1.style.color);
    //set
    h1.style.color=&quot;blue&quot;;
    //get
    console.log(h1.style.color);
}

h1.addEventListener(&quot;click&quot;, handleTitleClick);</code></pre>
<p>change color using if statement</p>
<pre><code class="language-javascript">const h1 = document.querySelector(&quot;div.hello:first-child h1&quot;);

function handleTitleClick() {
    if(h1.style.color===&quot;blue&quot;){
        h1.style.color=&quot;tomato&quot;;
    } else {
        h1.style.color=&quot;blue&quot;;
    }
}

h1.addEventListener(&quot;click&quot;, handleTitleClick);</code></pre>
<p>using const and let to change color</p>
<pre><code class="language-javascript">const h1 = document.querySelector(&quot;div.hello:first-child h1&quot;);

function handleTitleClick() {
    const currentColor = h1.style.color;
    let newColor;
    if(currentColor===&quot;blue&quot;){
        newColor=&quot;tomato&quot;;
    } else {
        newColor=&quot;blue&quot;;
    }
    h1.style.color=newColor;
}

h1.addEventListener(&quot;click&quot;, handleTitleClick);</code></pre>
<p>change style using css
css script</p>
<pre><code class="language-css">body{
    background-color:beige;
}

h1 {
    color: cornflowerblue;
}

.active{
    color:tomato;
}</code></pre>
<p>javascript code</p>
<pre><code class="language-javascript">const h1 = document.querySelector(&quot;div.hello:first-child h1&quot;);

function handleTitleClick() {
    h1.className=&quot;active&quot;
}
//javascript will modify html and css will be looking at the html

h1.addEventListener(&quot;click&quot;, handleTitleClick);</code></pre>
<p>if not active then the original color, when the class name is set to active then change the color indicated in css</p>
<pre><code class="language-javascript">const h1 = document.querySelector(&quot;div.hello:first-child h1&quot;);

function handleTitleClick() {
    if(h1.className ===&quot;active&quot;){
        h1.className=&quot;&quot;;
    } else {
        h1.className=&quot;active&quot;;
    }
}

h1.addEventListener(&quot;click&quot;, handleTitleClick);</code></pre>
<p>transition in css - the color fades in and fades out when you click on it</p>
<pre><code class="language-css">h1 {
    color: cornflowerblue;
    transition: color .5s ease-in-out;
}</code></pre>
<p>to prevent making mistakes when using id names we can use const to make a variable to repeat</p>
<pre><code class="language-javascript">const h1 = document.querySelector(&quot;div.hello:first-child h1&quot;);

function handleTitleClick() {
    const activeClass = &quot;active&quot;;
    if(h1.className ===activeClass){
        h1.className=&quot;&quot;;
    } else {
        h1.className=activeClass;
    }
}

h1.addEventListener(&quot;click&quot;, handleTitleClick);</code></pre>
<p>classList helps you work with the list of classes</p>
<p>if I want to add a new css but wants them to stay</p>
<pre><code class="language-css">.sexy-font{
    font-family: &#39;Franklin Gothic Medium&#39;, &#39;Arial Narrow&#39;, Arial, sans-serif;
}</code></pre>
<p>I can use classList so that the sexy-font would stay and the active would be added or removed everytime I click</p>
<pre><code class="language-javascript">const h1 = document.querySelector(&quot;div.hello:first-child h1&quot;);

function handleTitleClick() {
    const activeClass = &quot;active&quot;;
    if(h1.classList.contains(activeClass)){
        h1.classList.remove(activeClass)=&quot;&quot;;
    } else {
        h1.classList.add(activeClass);
    }
}

h1.addEventListener(&quot;click&quot;, handleTitleClick);</code></pre>
<p>toggle does the same thing with the whole if statement in javascript
if &quot;active&quot; is in the classList, toggle will remove &quot;active&quot; and if &quot;active&quot; is not in the classList, toggle will add &quot;active&quot; to the classList</p>
<pre><code class="language-javascript">const h1 = document.querySelector(&quot;div.hello:first-child h1&quot;);

function handleTitleClick() {
    h1.classList.toggle(&quot;active&quot;);
}

h1.addEventListener(&quot;click&quot;, handleTitleClick);</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[C#-Assignment5]]></title>
            <link>https://velog.io/@jisu_lee/C-Assignment5</link>
            <guid>https://velog.io/@jisu_lee/C-Assignment5</guid>
            <pubDate>Fri, 03 Feb 2023 18:07:14 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/jisu_lee/post/990e3f5c-7de4-4a40-a7b0-9169c9c8d0a9/image.png" alt=""></p>
<p>다섯 번째 작고 소듕한 과제(Petting Zoo)입니다.</p>
<p>첫 번째로는 main.cs 코드입니다.</p>
<pre><code class="language-cs">using System;

class Program {
  public static void Main (string[] args) {
    Zoo BtownZoo = new Zoo(&quot;Happy Pets&quot;, &quot;Bloomingon&quot;, 8);

    Animal[] arr = new Animal[] {
      new Goat(&quot;Goatee&quot;, 3, false, false, false),
      new Goat(&quot;Jeni&quot;, 4, true, true, true),
      new Goat(&quot;Jumper&quot;, 2, true, true, false),
      new Goat(&quot;Kid&quot;, 1, true, true, true),
      new Goat(&quot;Pete&quot;, 2, false, false, true),
      new Pony(&quot;Bolt&quot;, 3, false, 50, 5, true, false),
      new Pony(&quot;Colt&quot;, 4, true, 30, 10, true, true)
    };

    foreach (Animal a in arr) BtownZoo.AddAnimal(a);

    ZooOperations ZooInc = new ZooOperations(BtownZoo);
    ZooInc.Run();

  }
}</code></pre>
<p>다음으로는 zoo.cs 코드입니다.</p>
<pre><code class="language-cs">using System;
using System.Collections.Generic;

public class Zoo
{
  public string Name { get; set; }
  public string City { get; set; }
  public int Capacity { get; set; }
  public List&lt;Animal&gt; Animals {get; set; }

  public Zoo (string name, string city, int capacity)
  {
    Name = name;
    City = city;
    Capacity = capacity;
    Animals = new List&lt;Animal&gt;();
  }

  public void AddAnimal(Animal animal)
  {
    // ***** [CODE] *****
    // Only if there is capacity add the given animal.
    // Otherwise print a warning that the given animal is not added.
    // Hint: Use the ToString of the animal object.
    if (Animals.Count &lt; 8) Animals.Add(animal);
    else Console.WriteLine(&quot;Zoo is at capacity. Cannot add animal&quot; + &quot; &quot; + animal.GetType().Name + &quot; &quot; + animal.Name + &quot; (&quot; + animal.Age + &quot;/&quot; + animal.Female + &quot;)&quot;);
  }

  public void RemoveAnimal(string name) 
  {
    // ***** [CODE] *****
    // Look for the name of the animal and if found, 
    // remove it from the Animals list.
    var item = Animals.Find(x=&gt;x.Name == name);
    Animals.Remove(item);
  }

  public void ListAnimals()
  {
    string heading = String.Format(&quot;{0} in {1} (Capacity {2}/{3})&quot;, 
      Name, City, Animals.Count, Capacity);
    Console.WriteLine(heading);
    Console.WriteLine(&quot;&quot;.PadRight(heading.Length, &#39;-&#39;));

    // ***** [CODE] *****
    // Print the Animals list.
    foreach(Animal animal in Animals)
    {
    Console.WriteLine(animal);
    }
  }

  public void FeedAnimals()
  {
    // ***** [CODE] *****
    // Feed all the animals.
    foreach(Animal animal in Animals)
    {
      Console.WriteLine(animal.GetType().Name + &quot; &quot; + animal.Name + &quot; is fed&quot;);
    }
    Console.WriteLine(&quot;All animals are fed.&quot;);
  }

  public void ClearAnimals()
  {
    // ***** [CODE] *****
    // Clear the animals.
    ClearAnimals();
  } 
}</code></pre>
<p>다음은 animal.cs입니다.</p>
<pre><code class="language-cs">using System;

public abstract class Animal
{
  public string Name { get; set; }
  public int Age { get; set; }
  public bool Female { get; set; }
  public Animal(string name, int age, bool female)
  {
    Name = name;
    Age = age;
    Female = female;    
  }

  public override string ToString()
  {
    return String.Format(&quot;{0} {1} ({2}/{3})&quot;, this.GetType(), Name, Age, 
                         Female ? &quot;F&quot; : &quot;M&quot;); 
  }  

  public abstract void Eat();
}

interface Pet
{
  bool Playful { get; set; }
  bool Adoptable { get; set; }
}

interface Riding
{
  int MaxRiderWeight { get; set; }
  int RestBetweenRides { get; set; }
}

interface Cost
{
  double FeedCost { get; set; }
}

class Goat : Animal, Pet
{
  public bool Playful { get; set; }
  public bool Adoptable { get; set; }

  public override string ToString()
  {
    return String.Format(&quot;{0} {1}{2}&quot;,
                         base.ToString(), 
                         Playful ? &quot; Playful&quot; : &quot;&quot;, 
                         Adoptable ? &quot; Adoptable&quot; : &quot;&quot;);
  }

  public Goat(string name, int age, bool female) : base(name, age, female)
  {
  }

  public Goat(string name, int age, bool female, bool playful, bool adoptable) :
    base(name, age, female)
  {
    // ***** [CODE] *****
    // Set properties that are specific to this class.
    Playful = playful;
    Adoptable = adoptable;
  }

  public override void Eat()
  {
    Console.WriteLine(&quot;{0} {1} is fed.&quot;, this.GetType(), Name);
  }
}

class Pony : Animal, Pet, Riding
{
  public bool Playful { get; set; }
  public bool Adoptable { get; set; }

  private int maxWeight; 
  public int MaxRiderWeight { 
    get { return maxWeight; }
    set { 
      // ***** [CODE] *****
      // Do not allow more than 100 pounds or negative values. 
      // Default max is 100.
      maxWeight = 100;
      if (value&gt;100 || value&lt;0) Console.WriteLine(&quot;Not allowed value.&quot;);
      else maxWeight = value;
    }
  }

  private int restMinutes;
  public int RestBetweenRides { 
    get { return restMinutes; }
    set { 
      // ***** [CODE] *****
      // Do not less than 5 minutes rest
      // Default minimum is 5.
      restMinutes = 5;
      if (value&lt;5) Console.WriteLine(&quot;Not allowed value.&quot;);
      else restMinutes = value; 
    }
  }

  public override string ToString()
  {
    return String.Format(&quot;{0} {1}{2}{3}{4}&quot;,
                         base.ToString(), 
                         &quot;[max &quot;+ MaxRiderWeight + &quot; lbs] &quot;,
                         &quot;[rest &quot;+ RestBetweenRides + &quot; mins]&quot;,
                         Playful ? &quot; Playful&quot; : &quot;&quot;, 
                         Adoptable ? &quot; Adoptable&quot; : &quot;&quot;);
  }

  public Pony(string name, int age, bool female) : base(name, age, female)
  {
  }

  public Pony(string name, int age, bool female, int maxriderweight, int restbetweenrides, bool playful, bool adoptable) :
    base(name, age, female)
  {
    // ***** [CODE] *****
    // Set properties that are specific to this class.
    MaxRiderWeight = maxriderweight;
    RestBetweenRides = restbetweenrides;
    Playful = playful;
    Adoptable = adoptable;
  }

  public override void Eat()
  {
    Console.WriteLine(&quot;{0} {1} is fed.&quot;, this.GetType(), Name);
  }
}

// ***** [CODE] *****
// Code all there additional animal classes. They should implement the 
// required interfaces and provide ToString overrides as in Goat and Pony.
//
// class Peacock : Animal
class Peacock : Animal
{
  public Peacock(string name, int age, bool female) :
    base(name, age, female)
  {
  }
  public override void Eat()
  {
    Console.WriteLine(&quot;{0} {1} is fed.&quot;, this.GetType(), Name);
  }
}
// 
// class Pig : Animal, Pet
// Hint: Copy from Goat
class Pig : Animal, Pet
{
  public bool Playful { get; set; }
  public bool Adoptable { get; set; }

  public override string ToString()
  {
    return String.Format(&quot;{0} {1}{2}&quot;,
                         base.ToString(),
                         Playful ? &quot; Playful&quot; : &quot;&quot;, 
                         Adoptable ? &quot; Adoptable&quot; : &quot;&quot;);
  }

  public Pig(string name, int age, bool female) : base(name, age, female)
  {
  }

  public Pig(string name, int age, bool female, bool playful, bool adoptable) :
    base(name, age, female)
  {
    // ***** [CODE] *****
    // Set properties that are specific to this class.
    Playful = playful;
    Adoptable = adoptable;
  }

  public override void Eat()
  {
    Console.WriteLine(&quot;{0} {1} is fed.&quot;, this.GetType(), Name);
  }
}

// 
// class Donkey : Animal, Pet, Riding
// Hint: Copy from Pony
class Donkey : Animal, Pet, Riding
{
  public bool Playful { get; set; }
  public bool Adoptable { get; set; }

  private int maxWeight; 
  public int MaxRiderWeight { 
    get { return maxWeight; }
    set { 
      // ***** [CODE] *****
      // Do not allow more than 100 pounds or negative values. 
      // Default max is 100.
      maxWeight = 100;
      if (value&gt;100 || value&lt;0) Console.WriteLine(&quot;Not allowed value.&quot;);
      else maxWeight = value;
    }
  }

  private int restMinutes;
  public int RestBetweenRides { 
    get { return restMinutes; }
    set { 
      // ***** [CODE] *****
      // Do not less than 5 minutes rest
      // Default minimum is 5.
      restMinutes = 5;
      if (value&lt;5) Console.WriteLine(&quot;Not allowed value.&quot;);
      else restMinutes = value; 
    }
  }

  public override string ToString()
  {
    return String.Format(&quot;{0} {1}{2}{3}{4}&quot;,
                         base.ToString(), 
                         &quot;[max &quot;+ MaxRiderWeight + &quot; lbs] &quot;,
                         &quot;[rest &quot;+ RestBetweenRides + &quot; mins]&quot;,
                         Playful ? &quot; Playful&quot; : &quot;&quot;, 
                         Adoptable ? &quot; Adoptable&quot; : &quot;&quot;);
  }

  public Donkey(string name, int age, bool female) : base(name, age, female)
  {
  }

  public Donkey(string name, int age, bool female, int maxriderweight, int restbetweenrides, bool playful, bool adoptable) :
    base(name, age, female)
  {
    // ***** [CODE] *****
    // Set properties that are specific to this class.
    MaxRiderWeight = maxriderweight;
    RestBetweenRides = restbetweenrides;
    Playful = playful;
    Adoptable = adoptable;
  }

  public override void Eat()
  {
    Console.WriteLine(&quot;{0} {1} is fed.&quot;, this.GetType(), Name);
  }
}</code></pre>
<p>마지막으로 ZooOperations.cs 코드입니다.</p>
<pre><code class="language-cs">using System;
using System.IO;
using System.Collections.Generic;

public class ZooOperations
{
  private Zoo zoo { get; set; }

  public ZooOperations(Zoo z)
  {
    zoo = z;
  }

  public void Run()
  {
    string[] line;
    string input, command;
    do {
      Console.Write(&quot;Zoo Op &gt; &quot;);
      input = Console.ReadLine();
      line = input.Split(&#39;,&#39;);
      if (line.Length == 0) continue;
      command = line[0].ToLower();
      switch (command) {
        case &quot;help&quot;:
          Console.WriteLine(&quot;Commands: add clear feed help list remove quit&quot;);
          Console.WriteLine(&quot;Command line arguments are comma separated.&quot;);
          break;
        case &quot;exit&quot;:
        case &quot;quit&quot;:
        case &quot;q&quot;: 
          return;
        case &quot;add&quot;:
          AddAnimal(line);
          break;
        case &quot;clear&quot;:
          zoo.ClearAnimals();
          break;
        case &quot;feed&quot;:
          zoo.FeedAnimals();
          break;
        case &quot;list&quot;:
          zoo.ListAnimals();
          break;
        case &quot;remove&quot;:
          RemoveAnimal(line);
          break;
        default:
          Console.WriteLine(&quot;Error in Command&quot;);
          break;
      }
    } while(true);
  }

  private void AddAnimal(string[] cmd)
  {
    if (cmd.Length &lt; 4) { 
      Console.WriteLine(&quot;Error: Missing required arguments&quot;);
      return;
    }
    string kind = cmd[1].ToLower();
    string name = cmd[2];
    int age;
    int.TryParse(cmd[3], out age);
    bool female = Array.IndexOf(cmd, &quot;female&quot;) &gt; 0;
    bool playful = Array.IndexOf(cmd, &quot;playful&quot;) &gt; 0;
    bool adoptable = Array.IndexOf(cmd, &quot;adoptable&quot;) &gt; 0;
    switch (kind) {
      case &quot;peacock&quot;:
        // ***** [CODE] *****
        // Add code to create a new peacock and add it to the zoo.
        Animal peacock = new Peacock(name, age, female);
        zoo.AddAnimal(peacock);
        break;
      case &quot;goat&quot;:
        Animal goat = new Goat(name, age, female, playful, adoptable);
        zoo.AddAnimal(goat);
        break;
      case &quot;pig&quot;:
        // ***** [CODE] *****
        // Add code to create a new pig and add it to the zoo.
        // Hint: See how &quot;goat&quot; is done above.
        Animal pig = new Pig(name, age, female);
        zoo.AddAnimal(pig);
        break;
      case &quot;pony&quot;:
        if (cmd.Length &lt; 7) Console.WriteLine(&quot;Error: Missing arguments&quot;);
        else {
          int load, rest;
          int.TryParse(cmd[5], out load);
          int.TryParse(cmd[6], out rest);
          Animal pony = new Pony(name, age, female, load, rest, playful, adoptable);
          zoo.AddAnimal(pony);
        }
        break;
      case &quot;donkey&quot;:
        // ***** [CODE] *****
        // Add code to create a new donkey and add it to the zoo.
        // Hint: See how &quot;donkey&quot; is done above.
        Animal donkey = new Donkey(name, age, female);
        zoo.AddAnimal(donkey);
        break;        
      default:
        Console.WriteLine(&quot;Error in command&quot;);
        break;
    }
  }

  private void RemoveAnimal(string[] cmd)
  {
    if (cmd.Length &lt; 2) { 
      Console.WriteLine(&quot;Error: Remove needs an argument&quot;);
      return;
    }
    string name = cmd[1];
    zoo.RemoveAnimal(name);
  }

}</code></pre>
<p>최종 결과입니다.
<img src="https://velog.velcdn.com/images/jisu_lee/post/653db75f-a9f6-4566-b59b-a8ae3989c29f/image.png" alt=""></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Javascript Day1]]></title>
            <link>https://velog.io/@jisu_lee/Javascript-Day1</link>
            <guid>https://velog.io/@jisu_lee/Javascript-Day1</guid>
            <pubDate>Fri, 03 Feb 2023 17:40:04 GMT</pubDate>
            <description><![CDATA[<p><img src="https://velog.velcdn.com/images/jisu_lee/post/d8a12ab6-d5ec-42ee-adef-25ac882cd5eb/image.png" alt=""></p>
<p>Javascript 스터디를 시작하였습니다. 두근두근거리는 마음으로 nomadcoders 강의를 수강하기로 하였습니다. Lecture 1과 Lecture 2 기록용 필기입니다.</p>
<h4 id="2123-data-types">#2.1~2.3 (Data Types)</h4>
<pre><code class="language-javascript">let a = 5;
const b = 2;

const myName = &quot;jisu&quot;;
let veryLongVariableName =&quot;this is how it works&quot;;

console.log(a+b);
console.log(a*b);
console.log(&quot;hello &quot;+ myName);
console.log(veryLongVariableName);

veryLongVariableName = &quot;let can be changed&quot;;

console.log(veryLongVariableName);


/* const and let is similar, variables don&#39;t change in const, but let is for creating someone, you can update it later
we will never change &#39;const&#39; but we can update &#39;let&#39; variables
always use const, sometimes use let, never use var */</code></pre>
<h4 id="24-booleans">#2.4 (Booleans)</h4>
<pre><code class="language-javascript">const amIFAT = true;
console.log(amIFAT);

const amISLIM = null;
console.log(amISLIM);
/*the output is null, has value the value is null*/

let something;
console.log(something);
/*the output would be undefined, does not have a value*/</code></pre>
<h4 id="25-arrays">#2.5 (Arrays)</h4>
<pre><code class="language-javascript">const mon = &quot;mon&quot;;
const tue =&quot;tue&quot;;

const dayOfWeek = mon + tue;

console.log(dayOfWeek);
/* just a whole chunk of strings*/

const dayOfWeek2 = [mon, tue]; /*creating array of week*/
console.log(dayOfWeek2);
/* the output is &quot;mon&quot;, &quot;tue&quot;*/

/* or to create an array we could do*/
const dayOfWeek3 = [&quot;mon&quot;, &quot;tue&quot;, &quot;wed&quot;, &quot;thu&quot;, &quot;fri&quot;, &quot;sat&quot;];
console.log(dayOfWeek3[5]);
dayOfWeek3[5];
/*get the fifth of the array, starting with 0*/

dayOfWeek3[5]=&quot;saturday&quot; /*to change what&#39;s in the array*/

//Add one more day to the array
dayOfWeek3.push(&quot;sun&quot;);
console.log(dayOfWeek3);</code></pre>
<h4 id="26-objects">#2.6 (Objects)</h4>
<pre><code class="language-javascript">const player = {
    name: &quot;jisu&quot;,
    points: 10,
    fat: true,
};

console.log(player);
console.log(player.name);
console.log(player[&quot;name&quot;]);

player.fat=false;
//the property gets updated

player.lastName=&quot;potato&quot;;
//add new property

player.points = player.points + 15;
//get something from the object and update

//console is also an object just like player.name, console.log looks similar</code></pre>
<h4 id="2728-functions">#2.7~2.8 (Functions)</h4>
<pre><code class="language-javascript">function sayHello(nameOfPerson, age){
    console.log(&quot;Hello my name is &quot;+ nameOfPerson + &quot; and I&#39;m &quot; + age+ &quot;years old.&quot;);
}


sayHello(&quot;jisu&quot;, 22);
sayHello(&quot;nico&quot;, 23);
sayHello(&quot;jennings&quot;, 24);

//sayHello function takes two arguments, the name of the player and their age
</code></pre>
<p>function을 활용한 간단한 계산기 만들기</p>
<pre><code class="language-javascript">function plus(firstNumber,secondNumber){
    console.log(firstNumber+secondNumber);
}

plus(2,3)

function divide(a,b){
    console.log(a/b);
}
divide(12,3);</code></pre>
<p>function을 property 취급하기</p>
<pre><code class="language-javascript">const player = {
    name: &quot;jisu&quot;,
    sayHello: function(otherPersonName){
        console.log(&quot;hello &quot; + otherPersonName + &quot; nice to meet you!&quot;);
    },
};

console.log(player.name);
player.sayHello(&quot;lynn&quot;);</code></pre>
<h4 id="211-functions">#2.11 (Functions)</h4>
<pre><code class="language-javascript">const age = 96;
function calculateKrAge(ageOfForeigner){
    return ageOfForeigner+2;
}

const krAge = calculateKrAge(age);
//by using return, we replace the line that recalled the final result of the function

console.log(krAge);</code></pre>
<p>console.log 대신 return을 사용한 계산기</p>
<pre><code class="language-javascript">const calculator = {
    plus: function (a,b){
        return a+b;
    },
    minus: function (a,b){
        return a-b;
    },
    times: function (a,b){
          return a*b;
    },
      divide: function (a,b){
          return a/b;
    },
      power: function (a,b){
          console.log(&quot;hell0&quot;);
          return a**b;
          console.log(&quot;bye bye&quot;);
          //the output returns hello and a**b but does not return bye bye as the function finishes its job at &#39;return&#39;
    },
};


const plusResult = calculator.plus(2,3);
const minusResult = calculator.minus(plusResult,10);
console.log(plusResult);
console.log(minusResult);
</code></pre>
<h4 id="213215-conditionals">#2.13~2.15 (Conditionals)</h4>
<pre><code class="language-javascript">const age = prompt(&quot;How old are you?&quot;); 
//does not use this anymore because we cannot modify this message box, pause the javascript execution until the user inputs something
console.log(age);

console.log(typeof age);
//looks like a number but it is actually a string

console.log(typeof age, typeof parseInt (age));
//change the string into a number, we use parseInt
//if we try to take a string and put it into parseInt the output would be NaN (not a number)</code></pre>
<p>isNaN as condition (using if statement)</p>
<pre><code class="language-javascript">const age = parseInt(prompt(&quot;How old are you?&quot;)); 

console.log(isNaN(age));
//will return boolean, false=age is a number, true=age is NaN

if(isNaN(age)){
   console.log(&quot;Please write a number&quot;);
} else{
    console.log(&quot;Thank you for writing your age&quot;);
}  </code></pre>
<p>using elseif for more conditions</p>
<pre><code class="language-javascript">const age = parseInt(prompt(&quot;How old are you?&quot;)); 


if(isNaN(age) || age&lt;0){
   console.log(&quot;Please write a positive number&quot;);
} else if(age&lt;18){
    console.log(&quot;You are too young.&quot;);
} else if(age&gt;=18 &amp;&amp; age &lt;= 50){
    console.log(&quot;You can drink&quot;);
} else if(age &gt; 50 &amp;&amp; age &lt;=80){
    console.log(&quot;You should exercise&quot;);
} else if (age ===100){
    console.log(&quot;wow you are wise&quot;);
} else {
    console.log(&quot;Do whatever you want&quot;);
}

//and operator is &amp;&amp;, or operator is ||, equal is ===, not equal is !==</code></pre>
]]></description>
        </item>
        <item>
            <title><![CDATA[C#-Assignment4]]></title>
            <link>https://velog.io/@jisu_lee/C-Assignment4</link>
            <guid>https://velog.io/@jisu_lee/C-Assignment4</guid>
            <pubDate>Thu, 03 Nov 2022 02:00:47 GMT</pubDate>
            <description><![CDATA[<p>저의 작고 소중한 네 번째 과제(Mortgages)입니다. 이번에는 새롭게 배운 class와 object를 기반으로 코드를 짜보았습니다.</p>
<pre><code class="language-cs">using System;

// Create Mortgage Class
public class Mortgage
{
   // Declare properties for Loan, Rate &amp; Term
   public double Loan { get; set; }
   public double Rate { get; set; }
   public int Term {get; set;}

   // Create overload method for validation (double)
   public static double GetDouble(string prompt, double min, double max)
   {
     double number = 0.0;
        string input;
        bool valid;
      do
      {
         Console.Write(&quot;{0} ({1} &lt;= range &lt;= {2}) : &quot;, prompt, min, max);
input = Console.ReadLine();
            valid = double.TryParse(input, out number) &amp;&amp; number &gt;= min &amp; number &lt;= max;
            if (!valid) Console.WriteLine(&quot;Please enter a number in the correct range&quot;);
        } while (!valid);
        return number;

   }

   // Create overload method for validation (integer)
   public static int GetInt(string prompt, int min, int max)
   {
      string input;
      int number;
     bool valid;
      do
      {
         Console.Write(&quot;{0} ({1} &lt;= range &lt;= {2}) : &quot;, prompt, min, max);
        input = Console.ReadLine();
            valid = Int32.TryParse(input, out number) &amp;&amp; number &gt;= min &amp; number &lt;= max;
            if (!valid) Console.WriteLine(&quot;Please enter a number in the correct range&quot;);
        } while (!valid);
        return number;
   }

   // Setup read-only property for Payment
   private double _Payment;
   public double Payment 
   {
      get
      { 
         if (_Payment == 0) _Payment = CalcPayment(Loan, Rate, Term);
         return _Payment;
      }
   }

   // Setup read-only property for TotalCost
   private double _TotalCost;
   public double TotalCost 
   {
      get
      { 
         if (_TotalCost == 0) _TotalCost = CalcTotalCost(Payment, Term);
         return _TotalCost;
      }
   }

   // Setup read-only property for TotalInterest
   private double _TotalInterest;
   public double TotalInterest 
   {
      get
      { 
         if (_TotalInterest == 0) _TotalInterest = CalcTotalInterest(TotalCost, Loan);
         return _TotalInterest;
      }
   }

   // Create method to calculate the monthly payment amount
   public double CalcPayment(double principal, double annualRate, int months)
   {
      double output = 0;
      double Monthrate = annualRate / 12;
      output = (principal * (Monthrate * Math.Pow(1 + Monthrate,months))) / (Math.Pow(1 + Monthrate, months) - 1);
      return output;
   }

   // Create method to calculate the total cost
   public double CalcTotalCost(double payment, int months)
   {
      double output = 0;
      output = payment * months;
      return output;
   }

   // Create method to calculate the total interest
   public double CalcTotalInterest(double cost, double principal)
   {
      double output = 0;
      output = cost - principal;
      return output;
   }

   // Convert all values to a single string
   public override string ToString()
   {
      string output = &quot;&quot;;
      output = Loan.ToString(&quot;C2&quot;) + &quot;;&quot; + 
              Rate.ToString(&quot;P&quot;) + &quot;;&quot; +
              Term.ToString() + &quot;;&quot; +
              Payment.ToString(&quot;C2&quot;) + &quot;;&quot; +
              TotalCost.ToString(&quot;C2&quot;) + &quot;;&quot; +
              TotalInterest.ToString(&quot;C2&quot;);
      return output;
   }
}

public class Program
{
  public static void Main (string[] args) 
  {
     // Create values for the header and the separator
    int[] field = new int[] {16,10,8,15,16,16};

        string Header = &quot;Loan&quot;.PadLeft(field[0]) +   &quot;Rate&quot;.PadRight(field[1]) + &quot;Months&quot;.PadRight(field[2]) + &quot;Payment&quot;.PadRight(field[3]) + &quot;Total Cost&quot;.PadRight(field[4]) + &quot;Interest&quot;.PadRight(field[5]);

        string Separator = &quot; &quot;.PadLeft(field[0], &#39;=&#39;) + &quot; &quot;.PadLeft(field[1], &#39;=&#39;) + &quot; &quot;.PadLeft(field[2], &#39;=&#39;) +&quot; &quot;.PadLeft(field[3], &#39;=&#39;) +&quot; &quot;.PadLeft(field[4], &#39;=&#39;) +&quot; &quot;.PadLeft(field[5], &#39;=&#39;);


      //Ask for the user to input the mortgage product amount    
     string s;
     int i;
     bool IsInt = false;
     do
     {
        Console.WriteLine(&quot;How many mortgage products would you like to compare? (0 to 10)&quot;);
        s = Console.ReadLine();
        IsInt = Int32.TryParse(s, out i);
     } while (i&lt;0 || i&gt;10 || !IsInt);

     Mortgage[] m = new Mortgage[i];
     string[] CompileInfo = new string[i];
     int j;


    //Continue the loop for the amount of mortgage products the user inputted
     for(j = 0; j &lt; i; j++)
     {
        m[j] = new Mortgage();
        Console.WriteLine(&quot;Mortgage Product #{0}&quot;, j+1);
        m[j].Loan = Mortgage.GetDouble(&quot;Loan $&quot;, 10000, 1000000);
        m[j].Rate = Mortgage.GetDouble(&quot;Rate %&quot;, 0.1, 25) / 100;
        m[j].Term = Mortgage.GetInt(&quot;Term mo&quot;, 60, 360);
        CompileInfo[j] = m[j].ToString();
     }

    //Create header and the top separator
        Console.WriteLine(Header);
     Console.WriteLine(Separator);

    //Fill in the table by seperating the information that was stored in a single string
     for (int k=0; k &lt; i; k++)
      {
        string[] SeparateInfo = CompileInfo[k].Split(&#39;;&#39;);
        Console.WriteLine(SeparateInfo[0].PadRight(field[0]) +
                        SeparateInfo[1].PadRight(field[1]) +
                        SeparateInfo[2].PadRight(field[2]) +
                        SeparateInfo[3].PadRight(field[3]) +
                        SeparateInfo[4].PadRight(field[4]) +
                        SeparateInfo[5].PadRight(field[5]));
      }

    //Create bottom separator
     string Separator2 = &quot; &quot;.PadLeft((81), &#39;=&#39;);
  Console.WriteLine(Separator2);
  }
}</code></pre>
<p>집을 사기 위해 받는 대출(모기지-mortgage) 상품의 개수를 입력하면 그만큼의 loop를 형성하게 됩니다. 이후 loan (대출금액), rate(이자율), term month(상환하는 달 수)를 입력하면 매달 상환해야 하는 금액, 총 금액 및 이자와 함께 테이블에 저장하게 됩니다.</p>
<p>다음은 결과값입니다.
<img src="https://velog.velcdn.com/images/jisu_lee/post/d8c08bba-15cf-4434-88dc-6c937b7eee80/image.png" alt=""></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[C#-Assignment 3]]></title>
            <link>https://velog.io/@jisu_lee/C-Assignment-3</link>
            <guid>https://velog.io/@jisu_lee/C-Assignment-3</guid>
            <pubDate>Thu, 03 Nov 2022 01:52:53 GMT</pubDate>
            <description><![CDATA[<p>세 번째 작고 소듕한 과제(Class Roster)입니다.
다음은 main.cs의 코드입니다.</p>
<pre><code class="language-cs">using System;

public class Program
{
   public static void Main()
   {

    // set capacity
    const int Capacity = 40;

    // define arrays
    string[] LastName = new string[Capacity];
    string[] FirstName = new string[Capacity];
    string[] MiddleName = new string[Capacity];
    string[] PhoneNumber = new string[Capacity];
    string[] Email = new string[Capacity];
    string[] GPA = new string[Capacity];

    // define variables 
    string strLastName =&quot;&quot;;
    string strFirstName =&quot;&quot;;
    string strMiddleName =&quot;&quot;;
    string strPhone = &quot;&quot;;
    string Phone10digits = &quot;&quot;;
    string strphone1;
        string strphone2;
        string strphone3;
    string strEmail;
    string strGPA;
    double dblGPA;
    bool HasNumericDigits;
    bool IsValidPhoneNumber;

   // get user&#39;s lastname
        int size = 0;
    do 
    {
      do
      {
        Console.WriteLine (&quot;Last Name = &quot;);
        strLastName = Console.ReadLine();
      }
      while (Validate.HasNumericDigits(strLastName)&amp;&amp;strLastName!=&quot;&quot;);

      if (strLastName==&quot;&quot;) continue;

      LastName[size] = strLastName;


   // get user&#39;s firstname 
                  for (int y = 0; y &lt; Capacity; y++)
            {
                 Console.WriteLine (&quot;First Name = &quot;);
           strFirstName = Console.ReadLine();
                int firstLength = strFirstName.Length;

HasNumericDigits = Validate.HasNumericDigits(strFirstName);
                if (HasNumericDigits == true || firstLength == 0)
                {
                    continue;
                }
                else
        {
           FirstName[size] = strFirstName;
        }
break;
            }

   // get user&#39;s middlename
      do
      {
        Console.WriteLine (&quot;Middle Name = &quot;);
        strMiddleName = Console.ReadLine();
      }
      while (Validate.HasNumericDigits(strMiddleName));

      MiddleName[size] = strMiddleName;



   // get user&#39;s PhoneNumber
                  for (int a = 0; a &lt; Capacity; a++)
            {
            Console.WriteLine (&quot;Phone Number = &quot;);
            strPhone = Console.ReadLine();
IsValidPhoneNumber = Validate.IsValidPhoneNumber(strPhone, out Phone10digits);

                    if (strPhone == &quot;&quot;)
             {
                    PhoneNumber[size] = strPhone;
                }
          else if (IsValidPhoneNumber == false)
            {
                            continue;
                        }
                        else
                        {
                            strphone1 = Phone10digits.Insert(0, &quot;(&quot;);
                            strphone2 = strphone1.Insert(4, &quot;) &quot;);
                            strphone3 = strphone2.Insert(9, &quot;-&quot;);
                            PhoneNumber[size] = strphone3;
                        }
break;
                }

      // get user&#39;s email
      do
      {
        Console.WriteLine (&quot;Email = &quot;);
        strEmail = Console.ReadLine();
        if (strEmail == &quot;&quot;)
             {
                    Email[size] = strEmail;
                }
          else if (!Validate.IsValidEmail(strEmail) == true)
            {
                            continue;
                        }
                        else
                        {
                            Email[size] = strEmail;
                        }break;     
      }
      while (!Validate.IsValidEmail(strEmail));

      Email[size] = strEmail;


  // get user&#39;s GPA
         do
      {
        Console.WriteLine(&quot;GPA = &quot;);
        strGPA = Console.ReadLine();
        dblGPA = Convert.ToDouble(strGPA);
      } 
      while (0&gt;dblGPA &amp;&amp; dblGPA&gt;4);
      if(strGPA==&quot;&quot;)continue;

      string strGpa = Convert.ToString(dblGPA);

      GPA[size] = strGPA;

   //big do while loop
      size++;
    }
    while (size&lt; Capacity &amp;&amp; strLastName !=&quot;&quot;);

  //Print student table
  int[] field = new int[] {20,18,25,4};

    string Header = &quot;Name&quot;.PadRight(field[0]) +   &quot;Phone&quot;.PadRight(field[1]) + &quot;Email&quot;.PadRight(field[2]) + &quot;GPA&quot;.PadRight(field[3]);

    string Separator = &quot; &quot;.PadLeft(field[0], &#39;=&#39;) + &quot; &quot;.PadLeft(field[1], &#39;=&#39;) + &quot; &quot;.PadLeft(field[2], &#39;=&#39;) +&quot; &quot;.PadLeft(field[3], &#39;=&#39;);

        Console.WriteLine(Header);
        Console.WriteLine(Separator);

    for (int i =0; i &lt; size; i++)
    {
            Console.WriteLine((LastName[i] + &quot;, &quot; + FirstName[i] + &quot; &quot; + MiddleName[i]).PadRight(field[0]) + PhoneNumber[i].PadRight(field[1])+ Email[i].PadRight(field[2]) + GPA[i].PadRight(field[3]));

    }
    string Separator2 = &quot; &quot;.PadLeft((68), &#39;=&#39;);
  Console.WriteLine(Separator2);

//get avg gpa
int z = 0;
double sum=0;
for (z = 0; z &lt; size; z++)
         {
          sum+=double.Parse(GPA[z]);
           }
     Console.Write(&quot;There are &quot; + z + &quot; student(s) with an average GPA of {0}&quot;,Math.Round(sum/ (z),2));

  }
}</code></pre>
<p>다음은 validation.cs의 코드입니다. 해당 코드들은 위의 main.cs에서 이름, 전화번호, 이메일을 validate하는데 사용됩니다. 위에 Validate.()을 통해서 불러와 validation을 하게 되는 구조입니다.</p>
<pre><code class="language-cs">using System;

public class Validate {

  public static bool IsNumericDigit(char c) {
    return &#39;0&#39; &lt;= c &amp;&amp; c &lt;= &#39;9&#39;;
  }

  public static bool HasNumericDigits(string s) {
    foreach (char c in s)
      if (IsNumericDigit(c)) return true;

// Same loop written with for
//    for (int i = 0; i &lt; s.Length; i++)
//      if (IsNumericDigit(s[i])) return true;

    return false;
  }

  public static bool IsValidPhoneNumber(string s, out string strPhoneNumber) {
    strPhoneNumber = &quot;&quot;;
    for (int i=0; i &lt; s.Length; i++) {
      if (IsNumericDigit(s[i]))
        strPhoneNumber += s[i];
      else switch (s[i]) {
        case &#39;-&#39; :
        case &#39;.&#39; :
        case &#39; &#39; :
        case &#39;(&#39; :
        case &#39;)&#39; : 
          break;
        default:
          return false; 
      }
    }
    return strPhoneNumber.Length == 10;
  }

  public static bool IsValidEmail(string s) {
        string[] word;
        // Check the presence of exactly one @ character and non-empty user name
        word = s.Split(&#39;@&#39;);
        if (word.Length != 2 || word[0] == &quot;&quot;)
            return false;

        // Check the presence of exactly one dot character and non-empty domain name
        string domain = word[1];
        word = domain.Split(&#39;.&#39;);
        if (word.Length != 2 || word[0].Length == 0)
            return false;

        // Check the domain suffix
    string suffix = word[1];
        switch (suffix) {
            case &quot;com&quot;:
            case &quot;net&quot;:
            case &quot;org&quot;:
            case &quot;me&quot;:
      case &quot;edu&quot;:
                break;
            default:
                return false;
        }
        return true;
    }
}</code></pre>
<p>위 코드들을 통해 다음과 아웃풋을 도출하였습니다. 유저가 입력을 마치면 table에 모든 정보를 저장하고 학생들의 수와 학점 평균을 도출합니다.
<img src="https://velog.velcdn.com/images/jisu_lee/post/f1fb61e2-685a-4321-b6ac-3fea10e8deea/image.png" alt=""></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[C#-Assignment 2]]></title>
            <link>https://velog.io/@jisu_lee/C-Assignment-2</link>
            <guid>https://velog.io/@jisu_lee/C-Assignment-2</guid>
            <pubDate>Thu, 03 Nov 2022 01:41:19 GMT</pubDate>
            <description><![CDATA[<p>다음은 작고 소중한 두 번째 과제(Blooming Patios)입니다.</p>
<pre><code class="language-cs">class MainClass {
  public static void Main (string[] args) {
    //The user inputs the length, width, and depth into the system
    Console.WriteLine(&quot;Enter the dimensions of the patio in feet: &quot;);
    Console.WriteLine(&quot;Length: &quot;);
        string strLength = Console.ReadLine();
        Console.WriteLine(&quot;Width: &quot;);
        string strWidth = Console.ReadLine();
        Console.WriteLine(&quot;Depth: &quot;);
        string strDepth = Console.ReadLine();

    //System displays error if the user doesn&#39;t input a number
    double DValid;
    if (!Double.TryParse(strLength,out DValid))
    {
            Console.WriteLine(&quot;Patio dimension must be a number!&quot;);
            return;
        }

    if (!Double.TryParse(strWidth,out DValid))
    {
            Console.WriteLine(&quot;Patio dimension must be a number!&quot;);
            return;
        }

    if (!Double.TryParse(strDepth,out DValid))
    {
            Console.WriteLine(&quot;Patio dimension must be a number!&quot;);
            return;
        }

    //System converts the strings into doubles
    double DLength = Convert.ToDouble(strLength);
        double DWidth = Convert.ToDouble(strWidth);
    double DDepth = Convert.ToDouble(strDepth);

    //System displays error if the user doesn&#39;t input a positive number
    bool isSignValid = (DLength &gt; 0 &amp;&amp; DWidth &gt;0 &amp;&amp; DDepth &gt;0);
        if (isSignValid == false)
        {
            Console.WriteLine(&quot;Please enter a positive number&quot;);
            return;
        }

    //The user inputs the finish type into the system
    Console.WriteLine(&quot;Concrete surface can be Flat, Broomed, Stamped&quot; );
    Console.WriteLine(&quot;Finish (enter a valid finish type): &quot;);
        string strFinish = Console.ReadLine();

    //System displays error message if the finish type is invalid
    if (strFinish!=&quot;Stamped&quot; &amp;&amp; strFinish!=&quot;Broomed&quot; &amp;&amp; strFinish!=&quot;Flat&quot;)
    {
            Console.WriteLine(&quot;Invalid string type requested&quot;);
            return;
        }

    //System calculates the patio, volume, #of buggy trips, pouring time, and the additional time for the project
    double DPatio = DLength*DWidth;
    double DVolume = DLength*DWidth*DDepth;
    double DBuggy_Trips = Math.Ceiling(DVolume/9);
    double DPouring_Time = DBuggy_Trips*5;
    double DAdditional_Time=70;

    //Assign different additional time for each finish types
    double DFinish_Time=0;

        if (strFinish==&quot;Stamped&quot;)
        {
            DFinish_Time=0.2;
        }
        else if (strFinish==&quot;Broomed&quot;)
        {
            DFinish_Time=0.1;
        }
        else if (strFinish==&quot;Flat&quot;)
        {
            DFinish_Time=0;
        }

    //System calculates the total time of the project
    double DTotal_Time=DPouring_Time+ DFinish_Time*DPatio+ DAdditional_Time;

    //Output of the system
    Console.WriteLine(&quot;BloomingPatios Project Estimate&quot;);
    Console.WriteLine(&quot;---------------------------------------&quot;);
    Console.WriteLine(&quot;Patio Dimensions (L,W,D) : &quot; +DLength+&quot;, &quot;+DWidth+&quot;, &quot;+DDepth);
    Console.WriteLine(&quot;Concrete Finish : &quot;+strFinish);
    Console.WriteLine(&quot;Patio Area: &quot; +DPatio+ &quot; sqft&quot;);
    Console.WriteLine(&quot;Concrete Needed: &quot; +DVolume+ &quot; cubic ft&quot;);
    Console.WriteLine(&quot;Number of Buggy Trips: &quot; +DBuggy_Trips);
    Console.WriteLine(&quot;Total Project Time: &quot; +DTotal_Time+ &quot; minutes&quot;);

    }
}</code></pre>
<p>결과값은 다음과 같습니다. 사용자가 폭, 넓이, 깊이를 입력하고 concrete surface의 종류를 입력하면 전체 면적과 콘크리트가 필요한 넓이 및 전체 프로젝트 시간을 도출합니다.
<img src="https://velog.velcdn.com/images/jisu_lee/post/42e1e03d-548a-4bf6-93cb-4322adb8e224/image.png" alt="">
숫자가 아닌 string 혹은 공백이 입력되면 오류 문구를 나타내기도 합니다.
<img src="https://velog.velcdn.com/images/jisu_lee/post/25469aa4-9409-4851-9a33-1cd533404ba1/image.png" alt="">
지정된 string이 아닌 다른 값을 입력했을 때도 오류를 띄웁니다.
<img src="https://velog.velcdn.com/images/jisu_lee/post/b6c8f1b3-313c-4be3-a861-8cf76c954226/image.png" alt=""></p>
]]></description>
        </item>
    </channel>
</rss>