묻고답하기

도와 주세요.

밑의 내용에서 문제들(question) 1,2,3 이 있는데 순서대로 나옵니다.

그런데 혹시 랜덤(random)으로 나오게금 가능할까요?

어느 부분을 수정하면 될까요?

감사합니다.

밑의 사이트에서 가져왔습니다.

https://github.com/furkantasel/html-word-game

 

<html>

<head>

<script src="jquery.min.js"></script>

 

<!-- Latest compiled and minified CSS -->

<link rel="stylesheet" href="bootstrap.min.css">

 

<!-- Optional theme -->

<link rel="stylesheet" href="bootstrap-theme.min.css">

 

<!-- Latest compiled and minified JavaScript -->

<script src="bootstrap.min.js"></script>

 

<script type="text/javascript">

 

var currentQuestion = 0;

var currentLetter = 0;

var currentScore = 0;

var currentQuestionScore =0;

var openedLetterIndices = [];

var openedLetters = [];

 

var question_set = [ {question_number:1, question:"Star of the EARTH?", answer:"SUN", letters:3}, 

  {question_number:2, question:"Occupation", answer:"JOB", letters:3},

  {question_number:3, question:"Gossip", answer:"GRAPEWINE", letters:9},

];

$(document).ready( function()

 

{

 

$("#mainDiv").hide();

$("#letterDiv").hide();

$("#guessDiv").hide();

$("#goDiv").hide();

$("#scoreDiv").hide();

 

$("#goBtn").click(function(){nextWithAnswer($("#guess").val())});

});

 

function start()

{

$("#startDiv").hide();

$("#mainDiv").show();

$("#letterDiv").show();

$("#guessDiv").show();

$("#goDiv").show();

$("#scoreDiv").show();

 

currentQuestionScore = question_set[currentQuestion].letters*100;

$("#questionScore").html(currentQuestionScore); 

$("#score").html(currentScore); 

$("#question").html("<h1>"+question_set[currentQuestion].question+"</h1>");

//$("#goDiv").html("<span class='btn btn-success btn-md' id='goBtn' onclick='nextWithAnswer("+$("#guess").text()+")'>GO!</span>");

var buttons ="";

for (var i = 0; i < question_set[currentQuestion].letters; i++) {

buttons= buttons + "<span class='btn btn-primary btn-lg'>-</span>";

};

$("#letters").html(buttons);

 

}

 

function giveLetter()

{

if(currentQuestionScore>0){

currentQuestionScore = currentQuestionScore - 100;

$("#questionScore").html(currentQuestionScore); 

 

var flag = true;

var indexToBeOpened;

while(flag)

{

indexToBeOpened = Math.floor(Math.random()*question_set[currentQuestion].letters);

flag = $.inArray(indexToBeOpened,openedLetterIndices)>=0;

}

 

openedLetters.push(question_set[currentQuestion].answer.substring(indexToBeOpened,indexToBeOpened+1));

openedLetterIndices.push(indexToBeOpened);

var buttons = "";

for (var i = 0; i < question_set[currentQuestion].letters; i++) {

if($.inArray(i,openedLetterIndices)>=0)

{

buttons= buttons + "<span class='btn btn-primary btn-lg'>"+question_set[currentQuestion].answer.substring(i,i+1)+"</span>";

}else

{

buttons= buttons + "<span class='btn btn-primary btn-lg'>-</span>";

}

};

$("#letters").html(buttons);

 

if(openedLetterIndices.length == question_set[currentQuestion].letters)

{

$("#next").html("<span class='btn btn-warning btn-lg' onclick='next()'>Next</span>"); 

}

}

}

 

function next()

{

if(currentQuestion!= question_set.length-1)

{

$("#next").html("");

currentQuestion+=1;

currentScore+= currentQuestionScore;

currentQuestionScore = question_set[currentQuestion].letters*100;

 

currentLetter = 0;

openedLetterIndices = [];

openedLetters = [];

 

$("#questionScore").html(currentQuestionScore); 

$("#score").html(currentScore); 

$("#question").html("<h1>"+question_set[currentQuestion].question+"</h1>");

 

var buttons ="";

for (var i = 0; i < question_set[currentQuestion].letters; i++) {

buttons= buttons + "<span class='btn btn-primary btn-lg'>-</span>";

};

$("#letters").html(buttons);

}else

{

finale("");

}

}

 

function nextWithAnswer (answer) {

 

if(currentQuestion!= question_set.length-1)

{

if (answer.toLowerCase() === question_set[currentQuestion].answer.toLowerCase())

{

alert('Correct!');

currentQuestion+=1;

currentScore+= currentQuestionScore;

currentQuestionScore = question_set[currentQuestion].letters*100;

 

currentLetter = 0;

openedLetterIndices = [];

openedLetters = [];

 

$("#questionScore").html(currentQuestionScore); 

$("#score").html(currentScore); 

$("#question").html("<h1>"+question_set[currentQuestion].question+"</h1>");

 

var buttons ="";

for (var i = 0; i < question_set[currentQuestion].letters; i++) {

buttons= buttons + "<span class='btn btn-primary btn-lg'>-</span>";

};

$("#letters").html(buttons);

}else

{

alert('False!');

currentQuestion+=1;

currentScore-= currentQuestionScore;

currentQuestionScore = question_set[currentQuestion].letters*100;

 

currentLetter = 0;

openedLetterIndices = [];

openedLetters = [];

 

$("#questionScore").html(currentQuestionScore); 

$("#score").html(currentScore); 

$("#question").html("<h1>"+question_set[currentQuestion].question+"</h1>");

 

var buttons ="";

for (var i = 0; i < question_set[currentQuestion].letters; i++) {

buttons= buttons + "<span class='btn btn-primary btn-lg'>-</span>";

};

$("#letters").html(buttons);

}

}else

{

finale(answer);

}

 

}

 

function finale(answer)

{

$("#mainDiv").hide();

$("#letterDiv").hide();

$("#guessDiv").hide();

$("#goDiv").hide();

$("#scoreDiv").hide();

$("#startDiv").show();

 

if (answer.toLowerCase() === question_set[currentQuestion].answer.toLowerCase())

{

$("#startDiv").html("<div class='text-center'><h1>Your final score is "+(currentQuestionScore + currentScore)+"</h1><span class='btn btn-success btn-lg' onclick='location.reload()'>Replay</span></div>");

}else

{

$("#startDiv").html("<div class='text-center'><h1>Your final score is "+(currentScore-currentQuestionScore )+"</h1><span class='btn btn-success btn-lg' onclick='location.reload()'>Replay</span></div>");

}

 

}

 

 

</script>

</head>

<body>

<div class='row'>

<div class='jumbotron' id='startDiv'>

<div class='text-center'>

<h1>Push the button to START!</h1>

<span class='btn btn-success btn-lg' onclick='start()'>GO!</span>

</div>

</div>

</div>

<div class='row'>

<div class='jumbotron' id='mainDiv'>

<div class='text-center'>

<p>Question Score = <span id='questionScore'></span></p>

<span id='question'></span>

<span id='letters'></span><br><br>

<span id='next'></span>

  </div>

</div>

</div>

<div class='row'>

  <div class='col-md-2 col-md-offset-1' id='letterDiv'>

  <span class='btn btn-danger btn-md' onclick="giveLetter()">Give me a letter</span>

  </div>

  <div class='col-md-4' id='guessDiv'>

  <div class='input-group' >

  <span class='input-group-addon' >My guess is: </span>

  <input type='text' class='form-control' placeholder='Guess' id='guess'>

</div>

  </div>

  <div class='col-md-2' id='goDiv'>

  <span class='btn btn-success btn-md' id="goBtn">GO!</span>

  </div>

  <div class='col-md-3' id='scoreDiv'>

  Score: <span id='score'></span>

  </div>

</div>

</body>

</html>

 

 

 

글쓴이 제목 최종 글
XE 공지 글 쓰기,삭제 운영방식 변경 공지 [16] 2019.03.05 by 남기남
ppumweb 2단메뉴 [2] 2020.02.01 by LYG
마도로스 xe에서 헤더 태그에서 왜? \ 생길까요? 미치겠네요  
dkexpress 메인 도메인 변경 [3] 2020.01.31 by J__
난다요 게시판 모바일에서 pdf 다운시 오류  
뮨다 오디오 미디어 서버 구축?  
LYG 3차메뉴 표시 방법 이게 맞나요?  
박재국 사이트 로그인 문제 등 문의 드립니다 [1] 2020.01.29 by sejin7940
WhiteRose 무작위 회원가입 방지법? [2] 2020.01.27 by WhiteRose
joa**** xe설치 위치를 어떻게 찾는지 궁금합니다. [2] 2020.01.24 by joa****
초초보보 주소입력시 상세주소 에러 문제 file  
홈런볼11 특정 계정 로그인할때 사용한 ip 확인 방법 [1] 2020.01.21 by sejin7940
도킹맨 (팁) SCM Music Player 크롬에서 작동 안되시는 분들 참고하셔요 file  
inhyeparklee XEDITION 기본레이아웃 몇가지 여쭤봅니다ㅠㅠ +모바일 [2] file 2020.01.19 by inhyeparklee
밀가루 xe에서 로그인 하면 oops! 라고 나오는데... [1] 2020.01.17 by sejin7940
당나귀 모바일에서 메뉴와 메뉴간의 링크가 열리지 않는데 [1] 2020.01.17 by sejin7940
그남자7 관리자는 링크클릭이 되는데, 비로그인시에는 링크 클릭이 되지 않습니다. [1] 2020.01.17 by sejin7940
사랑해요XE 크롬 개발자 도구(크롬에서 F12 누른것) 으로 소스코드가 어느 파일에 위치에 있는지 확인 하는 방법? [8] file 2020.01.16 by 양싸나이
LYG dispMemberSignUpForm가 아닌 다른 페이지에서 회원가입이 가능할까요? [6] 2020.01.16 by LYG
마루밑다락방 관리자에서 회원추가시 잘못된 인증입니다! 라고 오류가 뜨는 경우 [1] 2020.01.15 by sejin7940
BJPlane 회원 그룹 이미지 file  
파아란물결 관리자페이지 로그인 관련 문의 드립니다. [3] 2020.01.10 by sejin7940
곰수니 모바일에서 pc버전으로 볼때 [2] 2020.01.10 by DoorWeb
JW KCB 휴대폰 본인인증 질문 드립니다. (초보입니다.) [1] 2020.01.10 by sejin7940
요시요시 안녕하세요 초보 조언좀부탁드립니다 [3] 2020.01.09 by sejin7940
당나귀 에디터 xpresseditor 사용이 불가 file  
sot 배너를 적용 하고 싶습니다. 전 초보초보입니당 ㅋㅋ [2] file 2020.01.08 by sot
당나귀 ckeditor가 글을 작성하고 등록하면 저장이 안 됩니다. [1] 2020.01.08 by sejin7940
유시연 윈도우에 apm 자동설치 시 어떤 방식으로 하시나요..? [2] 2020.01.08 by 기진곰
도킹스테이션 목록수정 버튼이 사라졌습니다 [2] file 2020.01.07 by 도킹스테이션
장년 스케치북5 모바일에서 본문아래 목록 바탕색 수정 질문. [2] 2020.01.06 by 장년