Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
uploading files to repo
  • Loading branch information
pcm20001 committed Feb 8, 2024
1 parent 58f81c1 commit 0ef0887
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 0 deletions.
4 changes: 4 additions & 0 deletions week-03/js/week-03.js
@@ -0,0 +1,4 @@
let a = "a";
for(let a = 0, a < 7, a++) {
}
console.log("#")
87 changes: 87 additions & 0 deletions week-04/index.html
@@ -0,0 +1,87 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Week 04</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">

</head>
<body>



<div class="container mt-5">
<div class="row">
<main class="col-sm-10 offset-sm-1 col-md-8 offset-md-2 col-lg-6 offset-lg-3 col-xl-4 offset-xl-4 ">
<h1>Escape Room (change me)</h1>
<p>Update this intro text. Escape room games are interactive puzzles that challenge players to find clues, solve riddles, and escape from a locked
room within a limited time. They can be played online or in real life, with various themes, stories, and difficulty
levels. Escape room games are fun and exciting, as they test the players' logic, creativity, teamwork, and communication
skills. They are also a great way to exercise the brain and relieve stress.</p>
</main>
</div>

<div class="row">
<main class="col-sm-10 offset-sm-1 col-md-8 offset-md-2 col-lg-6 offset-lg-3 col-xl-4 offset-xl-4 ">
<!-- Output goes here -->
</main>
</div>
</div>

<!-- JS Templates -->
<template id="confirm">
<div class="card mb-4">
<h5 class="card-header">Confirm</h5>
<div class="card-body">
<h5 class="card-title">Question</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<button class="btn btn-primary btn-true">OK</button>
<button class="btn btn-secondary btn-false">Cancel</button>
</div>
</div>
</template>

<template id="prompt">
<div class="card mb-4">
<h5 class="card-header">Prompt</h5>
<div class="card-body">
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">
<h5 class="card-title">What is Your Name?</h5>
</label>
<input type="text" class="form-control" id="exampleFormControlInput1" placeholder="Type your response...">
</div>
<button class="btn btn-primary btn-true">OK</button>
<button class="btn btn-secondary btn-false">Cancel</button>
</div>
</div>
</template>

<template id="alert">
<div class="card mb-4">
<h5 class="card-header">Alert</h5>
<div class="card-body">
<h5 class="card-title">Title</h5>
<p class="card-text">text</p>
<button class="btn btn-primary btn-true">OK</button>
<button class="btn btn-secondary btn-false">Cancel</button>
</div>
</div>
</template>


<!-- Don't touch! We need this script -->
<script type="module" src="../.core/js/main.js"></script>


<!-- Game framework -->
<script src="js/game-framework.js" type="module"></script>


<!-- Open the following file in an editor to complete your assignment. -->
<script src="js/main.js" type="module"></script>


</body>
</html>
108 changes: 108 additions & 0 deletions week-04/js/game-framework.js
@@ -0,0 +1,108 @@
/**
* Game Framework
* It's safe to ignore this file. It's just a helper for the game.
*
*/

// Get the templates
let confirmTmpl = document.querySelector('#confirm').content;
let promptTmpl = document.querySelector('#prompt').content;
let alertTmpl = document.querySelector('#alert').content;



function Confirm(question = '', helpText='', appendTo = 'main') {

if (typeof question == 'string' && question !== '') {

return new Promise((resolve, reject) => {

// documentFragment from string
let df = confirmTmpl.cloneNode(true);

df.querySelector('.card-title').textContent = question;
df.querySelector('.card-text').textContent = helpText;


df.querySelector('.btn-true').addEventListener('click', (event) => {
console.log('Promise Resolved', true)
resolve(true)
}, {once: true})

df.querySelector('.btn-false').addEventListener('click', (event) => {
console.log('Promise Resolved', false)
resolve(false)
}, { once: true })

document.querySelector(appendTo).appendChild(df)
});
}
}


function Alert(question = '', helpText = '', appendTo = 'main') {

if (typeof question == 'string' && question !== '') {

return new Promise((resolve, reject) => {

// documentFragment from string
let df = alertTmpl.cloneNode(true);

df.querySelector('.card-title').textContent = question;
df.querySelector('.card-text').textContent = helpText;

df.querySelector('.btn-true').addEventListener('click', (event) => {
console.log('Promise Resolved', true)
resolve(true)
}, { once: true })

df.querySelector('.btn-false').addEventListener('click', (event) => {
console.log('Promise Resolved', false)
resolve(false)
}, { once: true })

document.querySelector(appendTo).appendChild(df)
});
}
}


function Prompt(question = '', helpText = '', appendTo = 'main') {

if (typeof question == 'string' && question !== '') {

return new Promise((resolve, reject) => {

// documentFragment from string
let df = promptTmpl.cloneNode(true);

df.querySelector('.card-title').textContent = question;
// df.querySelector('.card-text').textContent = helpText;
let input = df.querySelector('input');

df.querySelector('.btn-true').addEventListener('click', (event) => {
console.log('Promise Resolved', input.value)
resolve(input.value)
}, { once: true })

df.querySelector('.btn-false').addEventListener('click', (event) => {
console.log('Promise Resolved', false)
resolve(false)
}, { once: true })

document.querySelector(appendTo).appendChild(df)
});
}
}


// Autoscroll to the bottom of the page
const resizeObserver = new ResizeObserver(entries =>
window.scrollTo(0, document.body.scrollHeight)
)

// start observing a DOM node
resizeObserver.observe(document.body)

export { Confirm, Alert, Prompt }
22 changes: 22 additions & 0 deletions week-04/test/test.example.js
@@ -0,0 +1,22 @@
import { assert } from 'https://unpkg.com/chai/chai.js';
import * as ctx from '../js/week-01.js';


describe("Variables:", function () {
describe("firstName", function () {
it("should be a valid string", function () {
assert.typeOf(ctx.firstName, 'string');
});
});
describe("age", function () {
it("should be a valid number", function () {
assert(Number.isInteger(ctx.age));
assert.isNumber(ctx.age);
});
});
describe("whyImTakingThisCourse", function () {
it("should be a valid string", function () {
assert.typeOf(ctx.whyImTakingThisCourse, 'string');
});
});
});

0 comments on commit 0ef0887

Please sign in to comment.