Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,27 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous">
<title>Excuse generator</title>
</head>
<body>
<h1>Excuse Generator</h1>
<p id="excuse">My dog ate my homework</p>

<div class="container-fluid">

<div class="row mt-5 mb-5">
<div class="col-12 text-center">
<h1>Excuse Generator</h1>
<h3>You will not believe me, but...</h3>
</div>
</div>

<div class="row">
<div class="col-12 mt-5 p-5 fs-1 text-center">
<p id="excuse" class="text-primary border border-2 border-dark rounded">My dog ate my homework</p>
</div>
</div>

</div>

<script src="./script.js"></script>
</body>
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ let action = ['ate', 'peed', 'crushed', 'broke'];
let what = ['my homework', 'my phone', 'the car'];
let when = ['before the class', 'when I was sleeping', 'while I was exercising', 'during my lunch', 'while I was praying'];

function randomSelector ( array ) {
return array[Math.floor(Math.random() * array.length)];
};

function generateExcuse() {
let whoRandom = who[Math.floor(Math.random() * who.length)];
let actionRandom = action[Math.floor(Math.random() * action.length)];
let whatRandom = what[Math.floor(Math.random() * what.length)];
let whenRandom = when[Math.floor(Math.random() * when.length)];
let whoRandom = randomSelector( who );
let actionRandom = randomSelector( action );
let whatRandom = randomSelector( what );
let whenRandom = randomSelector( when );

let excuse = `${whoRandom} ${actionRandom} ${whatRandom} ${whenRandom}`;

let excuse = whoRandom + ' ' + actionRandom + ' ' + whatRandom + ' ' + whenRandom;
return excuse;
}
return excuse;
};

window.onload = function () {
document.getElementById("excuse").innerHTML = generateExcuse();
Expand Down