묻고답하기

도와 주세요.

밑의 내용에서 문제들(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 남기남
엑스이다국어 XE에서 기본적으로 제공하는 다국어탭의 리스트명을 변경할 수 있나요? [2] file 2020.07.15 by XEANT.com
qkadpaksqhrtj 채팅사이트 pg사 연결.. [4] 2020.07.15 by XEANT.com
무한행복 XE color code 모바일 레이아웃 [1] 2020.07.15 by XEANT.com
상해파 게시글에 글 작성시 글은 작성은 되는데 글 목록으로 화면전환이 안됩니다. [1] 2020.07.15 by XEANT.com
MC조몽 스킨내 html 파일 링크 연결이 가능한가요? [2] 2020.07.13 by MC조몽
sst22 안녕하세요 호스팅 이전 후 문제좀 확인부탁드립니다. [1] 2020.07.10 by sejin7940
현수 내용 직접 추가 시 에러상황.. 급한데 [2] 2020.07.10 by 현수
미리내가족 txtyle 에서 admin으로 접속이 안됩니다. [2] file 2020.07.10 by sejin7940
손주사랑 메뉴버튼에 이미지를 넣었는데요 [2] file 2020.07.09 by 손주사랑
까까뭉 사이트 폐쇄 후 sql 파일 복원 [1] 2020.07.08 by Luatic™
ahhas**** xe edition 레이아웃 크기 수정하는 것이 반영되지 않는 이유가 무엇인가요? [2] 2020.07.08 by ahhas****
닉단 상세설정에서 저장하면 페이지가 초기화가 됩니다. [2] file 2020.07.07 by 닉단
도킹맨 이미지 닉네임과 글씨가 같이 표기되는 문제 어떻게 해야할까요? [1] file 2020.07.07 by sejin7940
모얼더 주소창에 표시되는 파라미터를 수정할 수 있을까요? [1] 2020.07.06 by sejin7940
JUNG 관리자메뉴초기화 [1] 2020.07.03 by sejin7940
JUNG 코아 업데이트 복구 방법 [1] 2020.07.03 by sejin7940
대한국인 [다국어 세트] lang.xml 번역에 대한 문의 [2] 2020.07.02 by 대한국인
도은 쇼핑몰(누리고) 다국어 사용 시 상품명 출력문제 [2] file 2020.07.02 by 도은
자연 엑스돔 XDOM 레이아웃 v2 검색 에러에 대해 자문을 구합니다. [2] 2020.07.01 by 자연
대한국인 DoorWeb 레이아웃 B(Door_cpB_limit) 메인페이지에서 제대로 외국어가 표시 안됩니다. file  
대한국인 DoorWeb 레이아웃 B, 메뉴가 무조건 대문자로 나오는 걸 해제하려면? [2] file 2020.06.30 by 대한국인
서기f576b 아이콘샵 분류 생성시 module_srl 값은 필수입니다. file  
누리 주소창의 상세주소 저장오류  
x뿌니x 웹프로그래밍 사이트 만들기 db 설정 [1] file 2020.06.23 by 제이와이엔소프트
Julian 시놀로지 NAS XE3 설치 문제 [2] file 2020.06.20 by Julian
홈런볼11 글 작성 기간에 대한 조건문 [2] 2020.06.18 by 홈런볼11
yongsdotcom 파도 이미지글 출력 위젯 모바일 섬네일 오류 file  
mediaq**** 댓글 이미지 첨부 처리 [1] 2020.06.15 by 제이와이엔소프트
AimJin 원하는 페이지만 ip주소를 입력해서 접속 가능하도록 설정 가능할까요? [4] 2020.06.15 by AimJin
yongsdotcom sweet mobile 사이드 메뉴 오류(안눌림) file