in the task 7 of our lesson when i make my self url in the inputField to be shorten but the program execute the url which i assign in the const url for instance when i make " Idiot question: when to use ';' and when not - #5 by 2timit" the executer shorten url which run is "Your shortened url is:
rebrand.ly/kbcz1n6" I don’t know why and this is my code :
// Information to reach API
const apiKey = '';
const url = 'https://api.rebrandly.com/v1/links';
// Some page elements
const inputField = document.querySelector('#input');
const shortenButton = document.querySelector('#shorten');
const responseField = document.querySelector('#responseField');
// AJAX functions
const shortenUrl = () => {
const urlToShorten = inputField.value;
const data = JSON.stringify({destination: urlToShorten});
fetch(url, {method: 'POST', headers: {
'Content-type': 'application/json',
'apikey': apiKey
}, body: data}).then(response => {
if(response.ok) {
return response.json()
}
throw new Error('Request failed!')
}, networkError => {
console.log(networkError.message)
}).then(jsonResponse => {
renderResponse(jsonResponse)
})
}
// Clear page and call AJAX functions
const displayShortUrl = (event) => {
event.preventDefault();
while(responseField.firstChild){
responseField.removeChild(responseField.firstChild)
}
shortenUrl();
}
shortenButton.addEventListener('click', displayShortUrl);