Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatSINEWAVE committed Jun 6, 2024
1 parent 17f75d8 commit 383d6ab
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const anotherBtn = document.getElementById('anotherBtn');
const descriptionEl = document.getElementById('description');
const ideaTextEl = document.getElementById('ideaText');

const apiUrl = 'https://itsthisforthat.com/api.php?json';
const apiUrl = 'https://corsproxy.io/?https://itsthisforthat.com/api.php?json';

inspireBtn.addEventListener('click', getIdea);
anotherBtn.addEventListener('click', getIdea);
Expand All @@ -13,17 +13,10 @@ function getIdea() {
inspireBtn.style.display = 'none';
anotherBtn.style.display = 'block';

fetch('https://itsthisforthat.com/api.php?json', { mode: 'no-cors' })
.then(response => {
if (response.ok) {
return response.text();
} else {
throw new Error('Request failed with status: ' + response.status);
}
})
fetch(apiUrl)
.then(response => response.json())
.then(data => {
const parsedData = JSON.parse(data);
const { this: thisValue, that: thatValue } = parsedData;
const { this: thisValue, that: thatValue } = data;
ideaTextEl.textContent = `You should make a ${thisValue} that will be used for ${thatValue}.`;
})
.catch(error => {
Expand Down

0 comments on commit 383d6ab

Please sign in to comment.