묻고답하기

도와 주세요.

밑의 내용에서 문제들(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 남기남
a11**** 게시판 비밀글 등록시 관리자 댓글 등록이 안됩니다. [2] 2019.07.23 by a11****
집합론집합론 회원가입 관련 문의합니다. [5] 2019.07.23 by 집합론집합론
74575 메인페이지를 수정하고자 합니다. [2] file 2019.07.23 by 74575
철가면준호 기본 레이아웃 푸터질문입니다 [2] file 2019.07.22 by 철가면준호
PLS 레이아웃 저장시 설정이 다 날라감 [1] 2019.07.22 by 빈터
미스터부엉 레이아웃 추가가 안되요! [1] file 2019.07.22 by DoorWeb
다랑어84420 이미지 삽입기를 통해 이미지 삽입 후 엑박이 뜹니다. [2] 2019.07.22 by SimpleCode
이주연743 Fatal error: Class 'Object' not found in /home/genulee0/public_html/xe/widgets/coinslider/coinslider.class.php on line 263 [3] 2019.07.21 by 이주연743
이주연743 웹사이트가 안되는데 잠깐 봐 주시겠어요? [8] 2019.07.21 by 이주연743
min 데이터이전시 파일명 변경되는 문제 [3] 2019.07.19 by sejin7940
infight**** xe 디버깅 문의 [2] 2019.07.18 by infight****
프리뷰 라이브스포츠방송 설치방법을 알고싶습니다 [1] 2019.07.17 by DoorWeb
보람 레이아웃편집이 안됩니다 [6] file 2019.07.17 by DoorWeb
yu**** xe admin은 접속불가능하고 사이트게시판만 관리할 수 있도록 하는 게 가능한가요? [2] 2019.07.17 by yu****
보람 서버에 설치된 환경을 확인하는 법 [2] file 2019.07.17 by 보람
infight**** 다국어로 작성한 게시판이 메인 페이지에서 안나오는 문제 문의 [4] 2019.07.16 by infight****
yu**** RSS 통합피드 사용체크, 게시판 피드관리 전체공개했는데도 피드기능이 잠겨있다고 뜹니다.  
so****483b1 사이트 메뉴 이름 한글명 입력 오류  
LYG 저작권 관련하여 질문 한가지 드립니다 [5] 2019.07.15 by 봄비
AimJin 스마트폰 네이버어플 브라우저에서만 내용이 안나와요. [1] 2019.07.15 by DoorWeb
MIC 회원그룹지정에서 [1] 2019.07.13 by DoorWeb
MIC default 레이어에서 서브메뉴가 보이지 않습니다. [2] file 2019.07.13 by MIC
행복안락 XEDITION 슬라이드 화면축소해도 이미지 중앙에 놓기 문의드립니다. [6] file 2019.07.13 by DoorWeb
SSUN 게시판에 진행상태를 넣기 [3] file 2019.07.12 by DoorWeb
153 관리자페이지 접속 불가와 게시판 사진 업로드 오류 질문드려요 [8] file 2019.07.12 by 153
희진 안녕하세요 ! 고수분들 한번만 봐주세요 [1] 2019.07.12 by SimpleCode
BJVolvo이현석 회원 정보 관리 애드온 [3] 2019.07.12 by 우주학개론
동혀니 오목 모듈 비싸게 구합니다. [1] 2019.07.11 by sejin7940
Julian 주소 리다이렉션 문제 [5] 2019.07.11 by 우주학개론
희진 안녕하세요ㅠㅠ! 도와주세요 ㅠㅠ [2] 2019.07.11 by 우주학개론