조건문_2020.10.26

2020. 10. 27. 18:32·BootCamp_Codestates/Pre Tech Blog

Achievement Goals

  • truthy와 falsy 가 조건문에서 작동하는 방식을 이해할 수 있다.
  • 논리 연산자에 대해 이해할 수 있다.
  • if 와 else if , else를 이해하고 무리없이 활용할 수 있다.
  • 복잡한 조건문을 활용하여 실생활에서 쉽게 마주할 수 있는 문제를 해결할 알고리즘을 짤 수 있다.

if문

if ( condition1 ) {
  statement1
}

condition1을 만족하면 statement1을 실행한다.

if~else문

if ( condition1 ) {
  statement1
} else {
  statement2
}

condition1을 만족하면 statement1을 실행하고, 만족하지 않으면 statement2를 실행합니다.

다중if문

if ( condition1 ) {
  statement1
} else if ( condition2 ) {
  statement2
}

condition1을 만족하면 statement1을 실행하고, condition2을 만족하면 statement2을 실행합니다.

if ( condition1 ) {
  statement1
} else if ( condition2 ) {
  statement2
} else {
  statement3
}

condition1을 만족하면 statement1을 실행하고, condition2을 만족하면 statement2을 실행하고, 둘 다 만족하지 않으면 statement3을 실행합니다.

중첩if문

<script>
        let userID = "Jaykim88";
        let userPW = "12344321";
        
        let id = prompt("Please, type your ID","");
        let pw = prompt("please, type your password","");
        
        if( userID == id){
            if( userPW == pw){
                document.write( id + ", welcome!");
            } else {
                document.write("Password is wrong");
            }
        } else {
            document.write("ID is wrong");
        }
</script>

ID가 맞다면 비밀번호를 물어본 후 일치 여부를 확인하고,

ID가 틀리면 ID가 잘못되었다고 리턴한다.

 

 

출처: webzz.tistory.com/64

 

 

 

 

조건문엔 반드시 비교 연산자가 필요하다.

***6가지 falsy 값***

 

: if 문에서 false로 변환되어, if구문이 실행되지 않는다.

 if (false), if(null), if(undefined), if(0), if(NaN), if(' ')

 

falsy test

 

문법 출처: www.codingfactory.net/10440

'BootCamp_Codestates > Pre Tech Blog' 카테고리의 다른 글

디버깅이란?  (0) 2020.10.28
반복문  (0) 2020.10.28
함수_2020.10.26  (0) 2020.10.27
타입기초_2020.10.26  (0) 2020.10.27
변수_ 2020.10.26  (0) 2020.10.27
'BootCamp_Codestates/Pre Tech Blog' 카테고리의 다른 글
  • 디버깅이란?
  • 반복문
  • 함수_2020.10.26
  • 타입기초_2020.10.26
JTB
JTB
웹/앱 개발 정보를 공유하고 있습니다.
  • JTB
    JTechBlog
    JTB
  • 전체
    오늘
    어제
    • All About Programming;)
      • Computer Science
        • Terminology and Concepts
        • Network
        • Operating System
        • Database
        • Data Structure
        • Web Development
      • Frontend
        • Javascript Essentials
        • Perfomance Optimization
        • JS Patterns
        • React
        • Next.js
        • Flutter
        • Testing
      • Backend
        • Node.js
      • DevOps
        • Docker & Kubernetes
      • Coding Test
        • LeetCode
        • Programmers
      • Tech Books & Lectures
        • Javascript_Modern JS Deep d..
        • Network_IT 엔지니어를 위한 네트워크 입문
      • Projects
        • PolyLingo_2025
        • Build Your Body_2024
        • JStargram_2021
        • Covid19 Tracker_2021
        • JPortfolio_2021
      • BootCamp_Codestates
        • TIL
        • TILookCloser
        • Pre Tech Blog
        • IM Tech Blog
        • Daily Issues and DeBugging
        • First Project
        • Final Project
        • Sprint Review
        • Good to Know
        • Socrative Review
        • HTML &amp; CSS
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • 글쓰기
    • 관리
  • 공지사항

  • 인기 글

  • 태그

    CPU scheduling algorithm
    Time complexity and Space complexity
    need a database
    js pattern
    VoiceJournal
    testing
    How memory manage data
    딥다이브
    스코프
    Data Structure
    TCP/IP
    database
    Shared resources
    Binary Tree BFS
    Operating System
    polylingo
    Network
    커리어
    Threads and Multithreading
    structure of os
    indie hacker
    모던 자바스크립트 Deep Dive
    이벤트
    프론트엔드 성능 최적화 가이드
    Javascript Essentials
    DOM
    자바스크립트 딥다이브
    leetcode
    자바스크립트
    mobile app
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
JTB
조건문_2020.10.26
상단으로

티스토리툴바