Skip to content

Commit

Permalink
Fill in the blank added
Browse files Browse the repository at this point in the history
  • Loading branch information
RasperRevision committed Mar 16, 2024
1 parent 25d7292 commit 3db2fc3
Show file tree
Hide file tree
Showing 2,191 changed files with 45,761 additions and 18 deletions.
69 changes: 53 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@
<h1 class="welcome_title pt-5 m-0 text-center"></h1>
<div class="flex-grow-1">
<div class="games d-flex p-5 w-100 h-100">
<button class="game btn text-white fs-1 bg-danger" style="flex-basis: 50%">Matchup</button>
<button class="game btn text-white fs-1 bg-success" style="flex-basis: 50%">Quiz</button>
<button class="game btn text-white fs-1 bg-danger game-matchup" style="flex-basis: 100%">Matchup</button>
<button class="game btn text-white fs-1 bg-success game-quiz" style="flex-basis: 100%">Quiz</button>
<button class="game btn text-white fs-1 bg-info game-blank" style="flex-basis: 100%">Fill in the Blank</button>
</div>
<div class="topics d-flex p-5 w-100 h-100">
<button class="topic btn text-white fs-1 bg-danger" style="flex-basis: 33.3%">Dynamics</button>
<button class="topic btn text-white fs-1 bg-warning" style="flex-basis: 33.3%">Melody</button>
<button class="topic btn text-white fs-1 bg-info" style="flex-basis: 33.3%">Articulation</button>

<div class="music-topics d-flex p-5 w-100 h-100">
<button class="topic btn text-white fs-1 bg-danger" style="flex-basis: 100%">Dynamics</button>
<button class="topic btn text-white fs-1 bg-warning" style="flex-basis: 100%">Melody</button>
<button class="topic btn text-white fs-1 bg-info" style="flex-basis: 100%">Articulation</button>
</div>

<div class="english-lit-topics d-flex p-5 w-100 h-100">
<button class="topic btn text-white fs-1 bg-danger" style="flex-basis: 100%">Macbeth quotes</button>
<button class="topic btn text-white fs-1 bg-warning" style="flex-basis: 100%">A Christmas Carol quotes</button>
</div>

<div class="subjects d-flex p-5 w-100 h-100">
<button class="subject btn text-white fs-1 bg-danger" style="flex-basis: 100%">Music</button>
<button class="subject btn text-white fs-1 bg-info" style="flex-basis: 100%">English Literature</button>
</div>
</div>
</section>
Expand Down Expand Up @@ -86,9 +95,14 @@ <h1 class="welcome_title pt-5 m-0 text-center"></h1>
const topics = document.querySelectorAll('.topic');
const games = document.querySelectorAll('.game');

const sparent = document.querySelector('.subjects');
const tparent = document.querySelector('.topics');
const gparent = document.querySelector('.games');
const subject_parent = document.querySelector('.subjects');
const music_topic_parent = document.querySelector('.music-topics');
const english_lit_topic_parent = document.querySelector('.english-lit-topics');
const game_parent = document.querySelector('.games');

const matchup_game = document.querySelector('.game-matchup');
const quiz_game = document.querySelector('.game-quiz');
const blank_game = document.querySelector('.game-blank');

let title = document.querySelector('.welcome_title');

Expand All @@ -109,31 +123,48 @@ <h1 class="welcome_title pt-5 m-0 text-center"></h1>
}
});

tparent.classList.add('d-none');
gparent.classList.add('d-none');
music_topic_parent.classList.add('d-none');
english_lit_topic_parent.classList.add('d-none');
game_parent.classList.add('d-none');

subjects.forEach(function (subject) {
subject.addEventListener('click', function () {
subject_chosen = subject.innerHTML;
sparent.classList.add('d-none');
tparent.classList.remove('d-none');
subject_parent.classList.add('d-none');
title.innerHTML = "Select a topic";
if (subject_chosen == "Music") {
music_topic_parent.classList.remove('d-none');
} else if (subject_chosen == "English Literature") {
english_lit_topic_parent.classList.remove('d-none');
}
});
});
topics.forEach(function (topic) {
topic.addEventListener('click', function () {
topic_chosen = topic.innerHTML;
tparent.classList.add('d-none');
gparent.classList.remove('d-none');
title.innerHTML = "Select a game";
game_parent.classList.remove('d-none');
if (subject_chosen == "Music") {
music_topic_parent.classList.add('d-none');
} else if (subject_chosen == "English Literature") {
english_lit_topic_parent.classList.add('d-none');
if (topic_chosen == "Macbeth quotes") {
matchup_game.classList.add('d-none');
quiz_game.classList.add('d-none');
} else if (topic_chosen == "A Christmas Carol quotes") {
matchup_game.classList.add('d-none');
quiz_game.classList.add('d-none');
}
}
});
});
games.forEach(function (game) {
game.addEventListener('click', function () {
game_chosen = game.innerHTML;
gparent.classList.add('d-none');
game_parent.classList.add('d-none');
title.classList.add('d-none');


if (game_chosen == "Matchup") {
document.querySelector(".match-up").classList.remove('d-none');
startMatchupStopwatch();
Expand All @@ -142,11 +173,17 @@ <h1 class="welcome_title pt-5 m-0 text-center"></h1>
document.querySelector(".quiz").classList.remove('d-none');
startQuizStopwatch();
quiz(subject_chosen, topic_chosen);
} else if (game_chosen == "Fill in the Blank") {
console.log("yes");
var jsonFile = (topic_chosen == "Macbeth quotes") ? 'macbeth.json' : 'christmas_carol.json';

window.location.href = '/matchup?json=' + encodeURIComponent(jsonFile);
}
});
});
}


start();
</script>

Expand Down
146 changes: 146 additions & 0 deletions matchup/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quote Masking Game</title>
<link href="/node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">

<style>
body {
height: 100vh;
}

.container {
max-width: 600px;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
</style>
</head>

<body class="bg-light d-flex align-items-center justify-content-center p-0 m-0">
<div class="container w-100 bg-white">
<h3 class="mb-4">Complete the quotation</h3>
<div class="fw-bold" id="themes"></div>
<div class="fs-5 mb-4" id="quote"></div>

<input class="form-control p-2 mb-3" type="text" id="input" placeholder="Enter your guess" autocomplete="off">

<button class="btn btn-success" id="submit-btn">Submit</button>
<button class="btn btn-warning d-none" id="next-btn">Next</button>

<div class="my-2" id="result"></div>
</div>

<script>
document.addEventListener("DOMContentLoaded", function () {
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}

function loadJSON(callback) {
var jsonFile = getParameterByName('json');
console.log('JSON file:', jsonFile);
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', jsonFile, true);
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == 200) {
callback(JSON.parse(xobj.responseText));
}
};
xobj.send(null);
}

function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}

const themesElement = document.getElementById("themes");
const quoteElement = document.getElementById("quote");
const inputElement = document.getElementById("input");
const submitButton = document.getElementById("submit-btn");
const nextButton = document.getElementById("next-btn");
const resultElement = document.getElementById("result");

let quotes;
let shuffledQuotes;
let currentQuoteIndex = 0;

function displayQuote() {
const quoteObj = shuffledQuotes[currentQuoteIndex];
const themesTitleCase = quoteObj.themes.map(theme => toTitleCase(theme));
themesElement.textContent = `${themesTitleCase.join(", ")}`;
quoteElement.textContent = maskQuote(quoteObj.quote);
}

function toTitleCase(str) {
return str.toLowerCase().split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
}


function maskQuote(quote) {
return quote.replace(/\b\w+(?:['’]\w+)?|[^\s]/g, match => {
if (match.trim() === "") return match;
if (/[^a-zA-Z]/.test(match)) return match;
if (Math.random() < 0.4) return "_".repeat(match.length);
else return match;
});
}

function checkInput() {
const userGuess = inputElement.value.trim();
const actualQuote = shuffledQuotes[currentQuoteIndex].quote;
resultElement.textContent = (userGuess.toLowerCase() === actualQuote.toLowerCase()) ? "Correct" : "Incorrect! The correct quote is: " + actualQuote;
submitButton.classList.add('d-none');
nextButton.classList.remove('d-none');
}

function nextQuote() {
currentQuoteIndex++;
if (currentQuoteIndex >= shuffledQuotes.length) {
currentQuoteIndex = 0;
shuffledQuotes = shuffle([...quotes]);
}
inputElement.value = "";
resultElement.textContent = "";
submitButton.classList.remove('d-none');
nextButton.classList.add('d-none');
displayQuote();
}

submitButton.addEventListener("click", function () { checkInput(); });
nextButton.addEventListener("click", function () { nextQuote(); });

inputElement.addEventListener("keypress", function (event) {
if (event.key === "Enter") {
event.preventDefault();
checkInput();
}
});

loadJSON(function (response) {
quotes = response;
shuffledQuotes = shuffle([...quotes]);
console.log(shuffledQuotes);
displayQuote();
});
});

</script>
</body>

</html>
Loading

0 comments on commit 3db2fc3

Please sign in to comment.