Skip to content

Asensio0227/Joke-vanilla.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Dad Jokes Project

HTML Structure

  • div.container
    • button.btn
    • p.result(dummy text)

External Data

  • the main idea the same, just external data

What is an API?

What is an API?

Docs

  • important
  • search engine
  • test in the browser

Dad Jokes Docs

Select Elements

  • select btn, result
  • check if both elements selected
  • listen for click events

FetchDadJoke Function

  • create async function
  • setup fetch
  • set result.textContent = joke
const fetchDadJoke = async () => {
  const response = await fetch(url, {
    headers: {c
    },
  });

  const data = await response.json();
  result.textContent = data.joke;
};

Loading

  • set result equal to - 'Loading...'

Error Handling

  • try/catch block
  • set result equal to - 'There was an error..'

Check Status

  • Fetch - only throws an error if cannot resolve
  • Error response still a response
  • check response.ok property
  • throw new Error('Whoops!')

Joke-vanilla.js

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published