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
39 changes: 17 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
# 📊 Project: Simple API 2

### Goal: Display data returned from an api

### How to submit your code for review:

- Fork and clone this repo
- Create a new branch called answer
- Checkout answer branch
- Push to your fork
- Issue a pull request
- Your pull request description should contain the following:
- (1 to 5 no 3) I completed the challenge
- (1 to 5 no 3) I feel good about my code
- Anything specific on which you want feedback!

Example:
```
I completed the challenge: 5
I feel good about my code: 4
I'm not sure if my constructors are setup cleanly...
```
# Simple API 2 Project

This project fetches a joke from a jokes API and display that joke on the UI!

## How It's Made:

**Tech used:** HTML, CSS, and JavaScript

I used html for the markup, css for the styling, andI used Javascript for the logic of this project.

## Lessons Learned:

I learned how to run javascript code in HTML strings, and turn the output into a number via the eval function.

## Image of Project:

![dadjokes image](dadjokesapiimg.png)
Binary file added dadjokesapiimg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>

<main>
<h2></h2>
<button>Get a Joke!</button>
</main>

<script src="script.js"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Get a Joke API PROJECT!


let button = document.querySelector('button')

button.addEventListener("click", getJoke)

function getJoke(){
let joke = document.querySelector('h2')
let API_URL = ' https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,racist,sexist&type=single'
fetch(API_URL)
.then(res => res.json())
.then(data => {
console.log(data)
joke.innerText = data.joke
})

}
53 changes: 53 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* box shadow citation https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow */
/* https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_transitions/Using_CSS_transitions */


* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: #abc5ec;
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
}

main {
background: #fff;
padding: 2rem;
border-radius: 10px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
max-width: 500px;
width: 90%;
text-align: center;
}

h2 {
min-height: 2em;
font-size: 1.3rem;
color: #333;
}

button {
padding: 10px 20px;
font-size: 1rem;
background: #4caf50;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background 0.2s ease;
}

button:hover {
background: #45a049;
}