https://www.npmjs.com/package/prompt-sync
prompt-sync
a synchronous prompt for node.js
www.npmjs.com
사용자 입력받기 코드 복사후 터미널에 붙여넣기하고 엔터
https://hianna.tistory.com/454
[Javascript] 난수 생성하기 (랜덤 숫자, Random Number)
Javascript로 난수를 생성하는 방법을 소개합니다. Math.random() 범위를 지정한 난수 생성하기 0~9 0~10 0~99 0~100 1~10 2~5 난수 생성 함수 만들기 (범위 지정) min <= number <= max ( max 값 포함) min <= nu..
hianna.tistory.com
const prompt = require('prompt-sync')();
//1단계 홀짝 숫자 만들기
//parseInt() 소수를 정수로
const num = parseInt((Math.random() * 100) % 2)
console.log(num)
//2단계 사용자 입력
const answer = readlineSync("ODD O? EVEN E?")
//삼항연산자
const condition1 = num === 0 && answer === "E"
const condition2 = num === 1 && answer === "O"
//num이 0이고 answer가 E || num이 1이고 answer가 O
const result = condition1 || condition2 ?"정답":"오답"
console.log(`최종결과는 ${result}`)
'자바스크립트' 카테고리의 다른 글
자바스크립트 : 알아야 될 용어정리 (0) | 2021.11.13 |
---|---|
Undefined 이해하기 (0) | 2021.11.11 |
제어문 if / switch / 삼항 조건연산자 (0) | 2021.11.08 |
let과 var의 차이 : 호이스팅 (0) | 2021.11.08 |
단위 변환 문제 (0) | 2021.11.08 |