• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    해결됨

io is not defined

21.09.19 23:48 작성 조회수 969

2

 

const socket = io('/');
const getElementById = (id=> document.getElementById(id|| null;

// get DOM element
const helloStrangerElement = getElementById('hello_stranger');
const chattingBoxElement = getElementById('chatting_box');
const formElement = getElementById('chat_form');

function helloUser() {
  const userName = prompt('What is your name?');
  socket.emit('new_user'userName);
  console.log(userName);
}

function init() {
  helloUser();
}

init();

 

io is not defined라고 뜨면서 prompt가 나오지 않습니다. scripts.js의 1라인을 주석철히하면 prompt는 뜨구요. 

 

어떻게 하면 해결할 수 있을까요?

(https://github.com/GroundP/random-chatting)

 

 

답변 1

답변을 작성해보세요.

1

안녕하세요!

https://github.com/GroundP/random-chatting/blob/master/views/index.hbs

이 부분이 문제인 것 같습니다!

scripts.js은 socket script 아래에 있어야 합니다! (scripts.js에서 socket 라이브러리를 사용하기 때문에) 지금 위 아래 둘 다 scripts.js가 삽입되어 있는데 위에 부분 지워주시면 됩니다!

GroundP님의 프로필

GroundP

질문자

2021.09.23

감사합니다!