Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Ex2 is added
  • Loading branch information
amirhshad committed Dec 13, 2020
commit 6c49686f71539347735824e3ce3cd1cf2579c2a6
4 changes: 2 additions & 2 deletions Week1/homework/js-exercises/getandomUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const axios = require('axios');
function axiosMethod() {
axios
.get('https://www.randomuser.me/api')
.then(function(respons) {
console.log(respons);
.then(function(response) {
console.log(response.data);
})
.catch(function(error) {
console.log(error)
Expand Down
42 changes: 42 additions & 0 deletions Week1/homework/js-exercises/humor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@


function xhrMethod() {
const xhr = new XMLHttpRequest();
const url = 'https://xkcd.now.sh/?comic=latest'
xhr.open('GET', url);
xhr.send();
xhr.onreadystatechange = processRequest;
function processRequest(e) {
if(xhr.readyState == 4 && xhr.status == 200) {
let response = JSON.parse(xhr.responseText);
document.getElementsByTagName('img').src = response.img;
console.log(response);
};
};
xhr.onerror = function() {
if (xhr.status != 200) {
alert (`Error ${xhr.status}: ${xhr.statusText}`);
};
};
};

xhrMethod();





function axiosMethod() {
axios
.get('https://xkcd.now.sh/?comic=latest')
.then(function(response) {
console.log(response.data);
document.getElementsByTagName('img').src = response.data.img;
})
.catch(function(error) {
console.log(error)
});
}


axiosMethod();
15 changes: 15 additions & 0 deletions Week1/homework/js-exercises/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>

<img src="" alt="">

<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="humor.js"></script>
</body>
</html>