Skip to content

Added random facts #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.env
node_modules
.vscode/*
.vscode/*
config/.env
2 changes: 0 additions & 2 deletions config/.env

This file was deleted.

19 changes: 18 additions & 1 deletion public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,21 @@ async function markIncomplete(){
}catch(err){
console.log(err)
}
}
}

document.querySelector('button').addEventListener('click', getFetch)

function getFetch(){
const url = 'https://uselessfacts.jsph.pl//random.json?language=en'

fetch(url)
.then(res => res.json())
.then(data => {
console.log(data)
document.querySelector('h3').innerText = data.text
document.querySelector('a').innerText = data.source_url
})
.catch(err => {
console.log(`error ${err}`)
});
}
7 changes: 7 additions & 0 deletions views/todos.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
<input type="submit">
</form>

<div>
<h1>Generate a random, useless fact to procrastinate here!</h1>
<button type="button" name="button">Get Fact</button>
<h3></h3>
<span>Source: </span><a href=""></span>
</div>

<a href="/logout">Logout</a>

<script src="js/main.js"></script>
Expand Down