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
15 changes: 15 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
body{
font-family: 'Roboto', sans-serif;
background: #9966ff;
color: #66ffff;
text-align: center;
}
img{
margin: 0 auto;
}

button{
background: #66ffff;
height: 23px;
width: 10%;
}
19 changes: 19 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<h1>Enter a meal</h1>
<input type="text" name="" value="">
<button type="button" name="button">Click!</button>
<h2></h2>
<p></p>
<img src="" alt="">
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
19 changes: 19 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//Example fetch using pokemonapi.co
document.querySelector('button').addEventListener('click', getFetch)

function getFetch(){
const choice = document.querySelector('input').value
const url = `https://www.themealdb.com/api/json/v1/1/search.php?s=${choice}`

fetch(url)
.then(res => res.json()) // parse response as JSON
.then(data => {
console.log(data)
document.querySelector('h2').innerText = data.meals[0].strMeal
document.querySelector('img').src = data.meals[0].strMealThumb
document.querySelector('p').innerText = data.meals[0].strInstructions
})
.catch(err => {
console.log(`error ${err}`)
});
}