묻고답하기

도와 주세요.

밑의 내용에서 문제들(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 남기남
도리 SCM Music Player에 대해 질문해봅니다. [2] 2019.08.10 by 랩퍼투혼
yu**** SEO 모듈만으로 모든페이지 메타태그 다 다르게 어떻게 하는지요..  
orangehome content 위젯에 document_srl 이용해서 글을 뽑아오려면요? [2] 2019.08.07 by orangehome
현님v HTTP 500 내부 서버 오류 또는 404 에러 문제 [7] 2019.08.07 by 현님v
에이치엔컴퍼니 게시판에서 날짜에 마우스 갖다대면 몇시간전 뜨는데 없앨 수 있나요? file  
미박 스킨 문제일까요? XE코어 문제일까요? file  
빈터 [질문]위젯 등 코드에서 “\” 자동 생성되는 오류 [3] 2019.08.06 by 미박
마꼬꼬 IWNV와 라이트세일 써보신 분 계신가요? [1] 2019.08.06 by HowtoXE
정경준 스트리밍 서버 구축관련해서 문의드립니다 ㅠㅠㅠㅠ [5] 2019.08.05 by 토리스
손주사랑 게시판 글쓰기 폰트 사이즈 질문 드림니다 [6] file 2019.08.05 by 손주사랑
피엔 갑자기 초기화되어 급하게 질문드립니다 ㅜ [4] 2019.08.05 by 피엔
프리뷰 모바일사용 편의성 이 오류나요 도와주세요 [4] 2019.08.05 by 프리뷰
xe초보의삶 로그인 폼 수정 방법 (사진포함) [2] file 2019.08.02 by xe초보의삶
오센 input 타입을 textarea로 수정했는데요 [1] 2019.08.02 by sejin7940
햄슈터 부트스트랩(bootstrap)에 제로보드 적용시 게시판글쓰기 애러 [5] 2019.08.02 by 햄슈터
제레미 테마 업데이트가 계속 돌아가는 데요 어떻게 해야 되나요? [1] 2019.08.02 by SimpleCode
쮸야282 맛집 포탈 만드는 중인데 위치기반... [2] 2019.08.01 by 제이와이엔소프트
lun**** 폰트 관련 문의 [1] 2019.08.01 by 제이와이엔소프트
제레미 게시글에 사진을 올렸다가 삭제 후 가비지 처리? [3] 2019.07.31 by 제레미
XE모듈 XE 게시판 글쓰기 속도가 너무 느립니다. [2] 2019.07.31 by 최윤한
m1n1me 스팸 회원 등록 [1] file 2019.07.30 by 제이와이엔소프트
빈터 로그인 에러 [1] 2019.07.30 by 빈터
yu**** XE 서브페이지나 게시판이 없을 경우, "RSS 피드 기능이 잠겨있습니다" 는 어떻게 해결해야할까요?  
본후야 MySQL-DB Connect 에러가 떠요. [6] file 2019.07.30 by 제이와이엔소프트
손주사랑 세상에 메인화면 로고사진을........ [9] file 2019.07.29 by 손주사랑
좋은세상6c009 상품 등록시  
디지털웍스 언어기반 스팸필터 써도 제목만 다는 스팸글 차단 불가!!! [1] file 2019.07.29 by 디지털웍스
헨델8 글,댓글 추천 log에 member_srl이 있다가 없다가하네요. (버그일까요?) [1] file 2019.08.08 by reactux
Lucida 페이지 홈 화면 게시판 메뉴를 클릭하면 홈 화면 아래쪽으로 게시판이 열립니다. [2] file 2019.07.29 by Lucida
손주사랑 기진곰님 FTP에서 바꾸었습니다 file