웹 공부/javascript

코딩 스터디(모각코) 13일차 - 한 입 웹개발(JS)

윈터가든 2021. 7. 30. 11:21

 오늘의 문제 : 챗봇 완성 시키기

 

✅ 오늘의 문제 풀이 인증

<HTML>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>javascript1</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Gamja+Flower&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="./12.css">
    <script src="./12.js"></script>

</head>

<body>
    <h2 class="main_name"><내 친구 싱아></h2>
    <div class="box">
        
        <a id="a">댕댕🐾</a>
    </div>
    

    <img src="img/싱아1.jpg" alt="" id="img" >
    
    <input type="text" id="text_box">
    <button onclick="btn_click()">시키기</button>
    

</body>

</html>

<CSS>

*{
    font-family: 'Gamja Flower', cursive;
    color: rgb(70, 36, 12);
}
.box{
    text-align: center;
    line-height: 200px;
    width: 380px;
    height: 200px;
    border-style: solid; 
    border-color: rgb(126, 91, 66);
    border-width:4px;
    border-radius: 5px;
    margin-bottom: 10px;
    margin-left: auto;
    margin-right: auto;
    font-size: 30px;
    position: relative;
   
}

#img{
    display: block;
   
    margin-bottom: 30px;
    margin-left: auto;
    margin-right: auto;
    position: relative;
   

}

input[type=text]{
   
    display: block;
    border: 3px solid peru;
    border-radius: 5px;
    height: 30px;
    width: 300px;
    font-size: 12pt;
    text-align: center;
    box-sizing: border-box;
    margin-bottom: 20px;
    margin-left: auto;
    margin-right: auto;
    position: relative;
   
    
   
    
}
button{
    display: block;
    margin-right: auto;
    margin-left: auto;
    background-color: navajowhite;
    border: none;
    border-radius: 30px;
    width: 200px;
    height: 50px;
    font-size: 30px;
    color: white;




}
#weather{
    text-decoration: none;
}
#all{
    background-color:rgba(0, 0, 0, 0.5);
    width: 100%;
}
.main_name{
    display:flex;
    justify-content: center;
}

<javascript>

function btn_click(){
    var text=document.getElementById('text_box').value;
    

    if(text=="싱아 안녕"){
       
       document.getElementById('a').innerHTML='언니 안녕!'
       document.getElementById('img').src="img/싱아2.gif";       
    }
    else if(text=="배가 왜이리 빵빵해?"){
        document.getElementById('a').innerHTML='엄마가 🍌조금 줬어';
        document.getElementById('img').src="img/싱아2.jpg";}

    else if(text=="뭐해?"){
            document.body.style.backgroundColor = '#606060'
            document.getElementById('a').innerHTML='잠잘 준비 중';
            document.getElementById('img').src="img/싱아4.jpg";
        
    }
    else if(text=="벌써? 나랑 놀자"){
        
        
        document.body.style.backgroundColor = '#ffffff'
        document.getElementById('a').innerHTML='5분민이다...';
        // document.getElementById('img').src="img/싱아4.jpg";
        
    }
    else if(text=="출근하기 싫다"){
        document.getElementById('a').innerHTML='언니 사료값은 벌어야지...';
        document.getElementById('img').src="img/싱아3.jpg";
        
    }}

<결과화면>

 

✅ 오늘의 한마디

기능들을 더 추가해서 완성도를 높이고 싶습니다.