모각코+/Javascript
[모각코+] 자바스크립트 12월과정 13일차
Jshrewd
2022. 1. 5. 18:34
728x90
https://cafe.naver.com/codeuniv/57490?boardType=L
[모각코+ 출석 인증] 13일차 - 웹 자바스크립트 12월 과정 A조
대한민국 모임의 시작, 네이버 카페
cafe.naver.com
챗봇 프로젝트 3일차입니다 !
이번에는 랜덤 난수를 활용해서 특정 사이트가 유도되게 했고, 특정 키워드만 인식해도 챗봇이 알아듣게 수정했어요 ~
HTML 파일
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Chat Bot</title>
<link rel="stylesheet" href="./day11-15.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Black+Han+Sans&family=Single+Day&display=swap');
</style>
</head>
<body id = "context">
<div class="layout">
<div id="cat_says">
쿨쿨쿨...
</div>
<div id="apeach">
</div>
<div class="input_layout">
<input type="text" id="text_input" class="input_style" placeholder="어피치에게 메세지를 보내주세요!">
</div>
<div class="w-btn-outline w-btn-pink-outline" onclick=check_text()>
시키기
</div>
</div>
</body>
<script src="./day11-15.js"></script>
</html>
JS 파일
let apeachUrl = "./getupapeach.jpg";
let apeachSleepUrl = "./sleepapeach.JPG";
let apeachEatUrl = "./eatapeach.jfif";
let apeachIntroUrl = "./introapeach.jfif";
let apeachCodingUrl = "./codingapeach.png";
let apeachFollowUrl = "./followapeach.png";
let apeachState = document.getElementById("apeach");
let apeachsays = document.getElementById("cat_says");
let body = document.getElementById("context");
let loginmsg = "큐셀님, 안녕하세요!";
let negamsg = "우...웅..? 무슨말이야..?";
let lightControl;
let follow = 0;
function check_text(){
let value = document.getElementById("text_input").value;
if(value.includes("일어") || (value.includes("불") && value.includes("켜"))){
if(lightControl==true){
apeachsays.innerHTML ="나 이미 일어나 있잖아 !";
lightControl = true;
}
else {
body.style.backgroundColor = "white"
apeachState.style.backgroundImage = "url('" + apeachUrl + "')";
change_text();
console.log(loginmsg);
lightControl=true;
}
}
else if(value.includes("불") && value.includes("꺼")){
if(lightControl==false){
apeachsays.innerHTML = "이미 꺼져있잖아!";
}
else {
body.style.backgroundColor = "#fcecf2"
apeachState.style.backgroundImage = "url('" + apeachSleepUrl + "')";
apeachsays.innerHTML = "나는 자러갈게..!";
lightControl = false;
}
}
else if(value.includes("먹어?")){
apeachState.style.backgroundImage = "url('" + apeachEatUrl + "')";
apeachsays.innerHTML = "복숭아를 먹지요~";
}
else if(value.includes("이름")){
apeachState.style.backgroundImage = "url('" + apeachIntroUrl + "')";
apeachsays.innerHTML = "내 이름은 어피치야!";
}
else if(value.includes("모각코") && value.includes("켜")){
apeachState.style.backgroundImage = "url('" + apeachCodingUrl + "')";
apeachsays.innerHTML = "너 코딩하려는구나 ~? 잠시만 기다려 !";
setTimeout(function(){
window.open("https://cafe.naver.com/codeuniv", "코뮤니티 모각코", "width=800, height=700, toolbar=no, menubar=no, scrollbars=no, resizable=yes");
},2000);
}
else if(value.includes("심심")){
let randomValue = Math.floor(Math.random() * 3) + 1;
if(randomValue == 1){
apeachState.style.backgroundImage = "url('" + apeachCodingUrl + "')";
apeachsays.innerHTML = "심심할 땐 유튜브지 ~";
setTimeout(function(){
window.open("https://www.youtube.com", "유튜브", "width=800, height=700, toolbar=no, menubar=no, scrollbars=no, resizable=yes");
},2000);
}
else if(randomValue == 2){
apeachState.style.backgroundImage = "url('" + apeachSleepUrl + "')";
apeachsays.innerHTML = "너가 심심하니까 나도 자러갈래...";
body.style.backgroundColor = "#fcecf2"
lightControl = false;
}
else {
apeachState.style.backgroundImage = "url('" + apeachIntroUrl + "')";
apeachsays.innerHTML = "공부해서 깃헙에 잔디나 심어 !";
setTimeout(function(){
window.open("https://github.com/", "깃허브", "width=800, height=700, toolbar=no, menubar=no, scrollbars=no, resizable=yes");
},2000);
}
}
else {
apeachsays.innerHTML = negamsg;
console.log(negamsg);
}
}
function change_text(){
apeachsays.innerHTML = loginmsg;
}
728x90