MASTER MIND MASTER MIND mastermind 1 Number Game there are 4 need to guess ,numbers from 0 to 9. show result by colour green, orange, red. Green means correct . Orange means this number is correct but in wrong place . Red means this is incorrect at all. Numbers: submit show results result: The correct answer is: you need restart this guess game number of green number of yellow
MASTER MIND MASTER MIND mastermind 1 Number Game there are 4 need to guess ,numbers from 0 to 9. show result by colour green, orange, red. Green means correct . Orange means this number is correct but in wrong place . Red means this is incorrect at all. Numbers: submit show results result: The correct answer is: you need restart this guess game number of green number of yellow
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
<!DOCTYPE html>
<html lang="en">
<head>
<title>MASTER MIND</title>
<link rel="stylesheet" type="text/css" href="1.css" />
</head>
<script type="text/javascript">
function MakeDot(colour) {
var string = '<span class="dot" style="background-color:';
switch (colour) {
case 'red':
string += '#ff0000';
break;
case 'green':
string += '#00cc00';
break;
case 'orange':
string += '#ff9900';
break;
default:
string += '#bbb';
break;
}
string += ';"></span>';
return string;
}
</script>
<body>
<div class="nav" id="nav">
<h2>MASTER MIND</h2>
<li><a id="game" href="index.html" target="_self">mastermind 1</a></li>
</div>
<div class="content" id="content">
<h1>Number Game</h1>
<div id="info">
there are 4 need to guess ,numbers from 0 to 9.<br />
show result by colour green, orange, red. <br />
<script>
document.write(MakeDot('green'));
</script>
Green means correct .<br />
<script>
document.write(MakeDot('orange'));
</script>
Orange means this number is correct but in wrong place .<br />
<script>
document.write(MakeDot('red'));
</script>
Red means this is incorrect at all.<br /><br />
</div>
<form id="form">
Numbers:
<input
type="number"
min="1000"
max="9999"
maxlength="1"
size="1"
id="number1"
autofocus
required
/>
<button id="evalBtn">submit</button>
</form>
<article class="d-flex">
<span class="ml-20 w-10"
>show <br />
results</span
>
<div class="results">
<h2 class="mt-0">result:</h2>
<span id="results"></span><br />
<span id="correctAnsSpan" class=""
>The correct answer is: <span id="txtcorrectans"></span> you need
restart this guess game
</span>
</div>
<span class="w-10"
>number of green
<br /><span id="txtcorrect"></span>
</span>
<span class="w-10"
>number of yellow
<br /><span id="txtincorrect"></span>
</span>
</article>
</div>
<script type="text/javascript">
// added event listener for evalBtn
let totalcorrect = 0;
let totalincorrect = 0;
document
.getElementById('evalBtn')
.addEventListener('click', function (e) {
var form = document.getElementById('form');
if (!form.checkValidity()) {
return true;
}
e.preventDefault();
submit();
document.getElementById('number1').value = '';
});
// add enter key as trigger:
var input = [document.getElementById('number1')];
// on pressing of enter when focused in input box,
// the button action will be initiated
for (let i = 0; i < input.length; i++) {
input[i].addEventListener('keyup', function (event) {
event.preventDefault();
let inputsSplitted = (input[0].value + '').split('');
if (inputsSplitted.length != 4) {
document.getElementById('evalBtn').disabled = true;
} else {
document.getElementById('evalBtn').disabled = false;
}
});
}
// generate guessing numbers:
var goal = [];
var length = 4;
goal[0] = Math.floor(Math.random() * 10);
for (let i = 1; i < length; ) {
var val = Math.floor(Math.random() * 10);
var flag = true;
// making sure that new number generated must be different from
for (let j = 0; j < i; j++) {
if (goal[j] == val) {
flag = false;
break;
}
}
if (flag == false) {
} else {
goal[i] = val;
i++;
}
}
console.log(goal, '%%%%%%%%%%%%%%%%%%');
// * Setting up limit for guess *
const guessLimit = 10;
var roundCounter = 0;
function submit() {
// check inputs for validity:
if (CheckInputs() == false) {
return;
}
// if guess limit reached
roundCounter++;
// prompting the user to tell how many guesses are left
alert(
`You have guessed ${roundCounter} times, you can guess ${
guessLimit - roundCounter
} times more `,
);
console.log(guessLimit, roundCounter);
if (guessLimit - roundCounter == 0) {
document.getElementById('correctAnsSpan').style.display = 'block';
document.getElementById('txtcorrectans').innerHTML = `${goal}`;
}
// save guessed numbers:
var guess = [];
// splitting the input so that if input was 1234 then it will split like [1,2,3,4]
let inputsSplitted = (input[0].value + '').split('');
for (let i = 0; i < inputsSplitted.length; i++) {
guess[i] = parseInt(inputsSplitted[i]);
}
// compare guessed numbers:
var guessCopy = guess.slice();
var goalCopy = goal.slice();
var evaluation = [];
let greencorrect = 0;
for (let i = 0; i < guessCopy.length; i++) {
if (
guessCopy[i] == goalCopy[i] &&
goalCopy[i] !== 'X' &&
guessCopy[i] !== 'X'
) {
evaluation[i] = 'green';
goalCopy[i] = 'X';
guessCopy[i] = 'X';
greencorrect += 1;
}
}
document.getElementById('txtcorrect').innerHTML += `${greencorrect}` + '<br>';
//count number of orange:
let orangecorrect = 0;
for (let i = 0; i < guessCopy.length; i++) {
if (goalCopy.indexOf(guessCopy[i]) != -1 && guessCopy[i] !== 'X') {
goalCopy[goalCopy.indexOf(guessCopy[i])] = 'X';
evaluation[i] = 'orange';
orangecorrect += 1;
} else if (
goalCopy.indexOf(guessCopy[i]) === -1 &&
guessCopy[i] !== 'X'
) {
//goalCopy[i] = "X";
evaluation[i] = 'red';
}
}
document.getElementById('txtcorrect').innerHTML += `${greencorrect}` + '<br>';
var correctCount = 0;
console.log(evaluation);
let bol = evaluation.includes('red');//line 227
--------------------------------
for this html ,i want to separate it into one html file and 1 js fiel ,but i cant do this work ,can anyone help me ?i dont know why my separate is wrong .
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education