묻고답하기

도와 주세요.

밑의 내용에서 문제들(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 남기남
옐로미모사 Err : './common/tpl/layout.html'  
홍찬 레이아웃에서 이미지 첨부시 썸네일로 사진 크기 조정  
당나귀 xe1에서 모바일 메뉴 배경색 변경  
karutian 머티리얼 디자인 이렇게는 못하나요 [2] 2020.02.28 by parangee
후레임 업데이트가 안되네요 [2] 2020.02.28 by 후레임
다이돌이 관리자 메일문의 게시판 위젯 스킨 카테고리로 글 등록되게 할려면...  
당나귀 홈페이지의 도메인 앞자리를 바꿀수 있나요? [2] 2020.02.27 by Eloy
당나귀 xe1로 제작한 홈페이지 ip를 어떻게 찾나요?  
똥베이런 선배님들 xe에 대해 공부를 시작하려고 합니다.  
야쿠 모바일 이용시 메인화면 [2] 2020.02.26 by 야쿠
소코반 글 쓸 때 HTML <> 가 사라집니다. [2] file 2020.02.25 by 소코반
프로다이버스사이판 플래닛 스킨 문제 [1] 2020.02.25 by XE
삼다수 스위트모바일(Sweetmoblie) 메인 Content 박스내 위젯 레이어 겹침 현상 문의 좀 드립니다 ㅜ  
흑괭이 다음 중 호스팅 어디가 괜챦을까요? [2] 2020.02.25 by 봄비
도킹맨 이 아이콘 이미지들은 어디에 저장되어있을까요? [2] file 2020.02.25 by 도킹맨
원스데일리라이프 첨부파일 이미지 슬라이드로 표현 [2] 2020.02.25 by 원스데일리라이프
Gambo PHP V7.2 에서 V7.3 변경시 문제 [3] 2020.02.24 by sejin7940
피카소 분류창의 크기를 어떻게 하면 늘릴수 있을까요? [2] file 2020.02.24 by 피카소
봄비 PC 첨부파일 권한, 모바일 첨부파일 권한 [2] 2020.02.24 by 봄비
봄비 게시판 에디터 어떻게 바꾸나요? [1] file 2020.02.24 by 봄비
JW 회원목록 검색 안되는 문제 [10] 2020.02.23 by 봄비
붉은석양 게시판 첨부파일 다운로드는 로그인 반복만 됩니다. [4] file 2020.02.22 by 붉은석양
mediaq**** https 이미지 [4] 2020.02.21 by mediaq****
오드리오 게시판 글쓰기 오류( 소스코드가 출력되요 ) [2] 2020.02.21 by 오드리오
hyosik 아이디/비번 찾기 500에러 페이지 연결  
WhiteRose URL이 변경되어 보이지 않는 이유?  
카이4525b 회원가입 생일 달력이 안나와요 ㅠㅠ [4] file 2020.02.21 by WhiteRose
hyosik 이메일 주소로 계정 찾기 오류 [1] 2020.02.18 by hyosik
WhiteRose Contend Media - bxslider 작동불가 [1] 2020.02.18 by WhiteRose
홈런볼11 일정기간 이후 모두 db 삭제 명렁어 [1] 2020.02.17 by sejin7940