forked from HackYourFuture/JavaScript3
-
Notifications
You must be signed in to change notification settings - Fork 2
Week1 masoud #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Week1 masoud #1
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d81fb0f
Ex1
massam89 e605f25
Ex2
massam89 b24742c
Ex3
massam89 be70ba1
code along
massam89 f291093
Finished Project week1
massam89 0f905ea
Fixed conflicts by adding to my name's folder
massam89 da76e87
change folder
massam89 224295c
Merge pull request #1 from samravan/master
massam89 e9773e6
fixed
massam89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| const number = document.getElementById('number'); | ||
| const fact = document.getElementById('fact'); | ||
|
|
||
| number.addEventListener('input', addText); | ||
|
|
||
| function addText(){ | ||
| const num = number.value; | ||
| const URL = `http://numbersapi.com/${num}`; | ||
|
|
||
| const xhr = new XMLHttpRequest(); | ||
| xhr.open('GET', URL, true); | ||
| xhr.send(); | ||
|
|
||
| // 4. This will be called after the response is received | ||
| xhr.onload = function() { | ||
| if (xhr.status != 200 && xhr.status != 200) { | ||
| // analyze HTTP status of the response | ||
| console.log(`Error ${xhr.status}: ${xhr.statusText}`); // e.g. 404: Not Found | ||
| } else { | ||
| // show the result | ||
| let response = xhr.responseText; | ||
| fact.style.display = 'block'; | ||
| fact.textContent = response; | ||
| } | ||
| }; | ||
|
|
||
| xhr.onprogress = function(event) { | ||
| if (event.lengthComputable) { | ||
| console.log(`Received ${event.loaded} of ${event.total} bytes`); | ||
| } else { | ||
| console.log(`Received ${event.loaded} bytes`); // no Content-Length | ||
| } | ||
| }; | ||
|
|
||
| xhr.onerror = function() { | ||
| console.log('Request failed'); | ||
| }; | ||
|
|
||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Number API</title> | ||
| <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous"> | ||
| </head> | ||
|
|
||
| <body class="bg-secondary"> | ||
| <div class="container mx-auto text-center mt-4" style="width: 400px;"> | ||
| <div class="card bg-primary text-white"> | ||
| <div class="card-body"> | ||
| <h5 class="card-title">Number Facts</h5> | ||
| <label class="mb-2" for="number">Please enter number in order to find out</label> | ||
| <br> | ||
| <input id="number" type="number" placeholder="Enter Number"> | ||
| <p id="fact" class="mt-4" style="display: none;"></p> | ||
| </div> | ||
|
|
||
|
|
||
| </div> | ||
| </div> | ||
|
|
||
|
|
||
| <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script> | ||
| <script src="app.js"></script> | ||
| </body> | ||
|
|
||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| const URL = 'https://www.randomuser.me/api'; | ||
|
|
||
| function requestWithXHR(URL){ | ||
| const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; | ||
| const xhr = new XMLHttpRequest(); | ||
| xhr.open('GET', URL, true); | ||
| xhr.send(); | ||
|
|
||
| // 4. This will be called after the response is received | ||
| xhr.onload = function() { | ||
| if (xhr.status != 200 && xhr.status != 200) { // analyze HTTP status of the response | ||
| console.log(`Error ${xhr.status}: ${xhr.statusText}`); // e.g. 404: Not Found | ||
| } else { // show the result | ||
| const response = JSON.parse(xhr.responseText); | ||
| console.log(response.results[0].gender); | ||
| } | ||
| }; | ||
|
|
||
| xhr.onprogress = function(event) { | ||
| if (event.lengthComputable) { | ||
| console.log(`Received ${event.loaded} of ${event.total} bytes`); | ||
| } else { | ||
| console.log(`Received ${event.loaded} bytes`); // no Content-Length | ||
| } | ||
|
|
||
| }; | ||
|
|
||
| xhr.onerror = function() { | ||
| console.log("Request failed"); | ||
| }; | ||
| }; | ||
|
|
||
| function requestWithAxios(URL){ | ||
| const axios = require('axios').default; | ||
| axios.get(URL) | ||
| .then(function (response) { | ||
| // handle success | ||
| console.log(response.data.results[0].gender); | ||
| }) | ||
| .catch(function (error) { | ||
| // handle error | ||
| console.log("Request failed"); | ||
| }) | ||
| .then(function () { | ||
| // always executed | ||
| }); | ||
|
|
||
| }; | ||
|
|
||
| requestWithXHR(URL); | ||
| requestWithAxios(URL); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| const URL = 'https://xkcd.now.sh/?comic=latest'; | ||
| const image1 = document.getElementById('image1'); | ||
| const image2 = document.getElementById('image2'); | ||
|
|
||
| function requestWithXHR(URL){ | ||
| const xhr = new XMLHttpRequest(); | ||
| xhr.open('GET', URL, true); | ||
| xhr.send(); | ||
|
|
||
| // 4. This will be called after the response is received | ||
| xhr.onload = function() { | ||
| if (xhr.status != 200 && xhr.status != 200) { // analyze HTTP status of the response | ||
| console.log(`Error ${xhr.status}: ${xhr.statusText}`); // e.g. 404: Not Found | ||
| } else { // show the result | ||
| const response = JSON.parse(xhr.responseText); | ||
| console.log(response); | ||
| image1.src = response.img; | ||
| } | ||
| }; | ||
|
|
||
| xhr.onprogress = function(event) { | ||
| if (event.lengthComputable) { | ||
| console.log(`Received ${event.loaded} of ${event.total} bytes`); | ||
| } else { | ||
| console.log(`Received ${event.loaded} bytes`); // no Content-Length | ||
| } | ||
|
|
||
| }; | ||
|
|
||
| xhr.onerror = function() { | ||
| console.log("Request failed"); | ||
| }; | ||
| }; | ||
|
|
||
| function requestWithAxios(URL){ | ||
| axios.get(URL) | ||
| .then(function (response) { | ||
| // handle success | ||
| console.log(response.data); | ||
| image2.src = response.data.img; | ||
| }) | ||
| .catch(function (error) { | ||
| // handle error | ||
| console.log("Request failed"); | ||
| }) | ||
| .then(function () { | ||
| // always executed | ||
| }); | ||
|
|
||
| }; | ||
|
|
||
| requestWithXHR(URL); | ||
| requestWithAxios(URL); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <!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 id="image1"> | ||
| <img id="image2"> | ||
| <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> | ||
| <script src="Ex2-ProgrammerHumor.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| const URL = 'https://dog.ceo/api/breeds/image/random'; | ||
| const xmlBtn = document.getElementById('xmlBTN'); | ||
| const axiosBtn = document.getElementById('axiosBTN'); | ||
| const ulElm = document.getElementById('list'); | ||
| const imgSize = '300px'; | ||
| ulElm.style.display = 'flex'; | ||
| ulElm.style.flexWrap = 'wrap'; | ||
|
|
||
| xmlBtn.addEventListener('click',requestWithXHR); | ||
| axiosBtn.addEventListener('click',requestWithAxios); | ||
|
|
||
|
|
||
| function requestWithXHR() { | ||
| const xhr = new XMLHttpRequest(); | ||
| xhr.open('GET', URL, true); | ||
| xhr.send(); | ||
|
|
||
| // 4. This will be called after the response is received | ||
| xhr.onload = function() { | ||
| if (xhr.status != 200 && xhr.status != 200) { | ||
| // analyze HTTP status of the response | ||
| console.log(`Error ${xhr.status}: ${xhr.statusText}`); // e.g. 404: Not Found | ||
| } else { | ||
| // show the result | ||
| const response = JSON.parse(xhr.responseText); | ||
| const liElm = document.createElement('li'); | ||
| const imgElm = document.createElement('img'); | ||
| imgElm.src = response.message; | ||
| imgElm.style.height = imgSize; | ||
| liElm.style.listStyle = 'none'; | ||
| liElm.appendChild(imgElm); | ||
| ulElm.appendChild(liElm); | ||
| } | ||
| }; | ||
|
|
||
| xhr.onprogress = function(event) { | ||
| if (event.lengthComputable) { | ||
| console.log(`Received ${event.loaded} of ${event.total} bytes`); | ||
| } else { | ||
| console.log(`Received ${event.loaded} bytes`); // no Content-Length | ||
| } | ||
| }; | ||
|
|
||
| xhr.onerror = function() { | ||
| console.log('Request failed'); | ||
| }; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| function requestWithAxios(){ | ||
| axios.get(URL) | ||
| .then(function (response) { | ||
| // handle success | ||
| const liElm = document.createElement('li'); | ||
| const imgElm = document.createElement('img'); | ||
| imgElm.src = response.data.message; | ||
| imgElm.style.height = imgSize; | ||
| liElm.style.listStyle = 'none'; | ||
| liElm.appendChild(imgElm); | ||
| ulElm.appendChild(liElm); | ||
| }) | ||
| .catch(function (error) { | ||
| // handle error | ||
| console.log("Request failed"); | ||
| }) | ||
| .then(function () { | ||
| // always executed | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <!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> | ||
| <ul id="list"></ul> | ||
| <button id="xmlBTN">Run as XMLHttpRequest</button> | ||
| <button id="axiosBTN">Run as axios</button> | ||
|
|
||
| <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> | ||
| <script src="Ex3-DogPhotoGallery.js"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| * { | ||
| padding: 0; | ||
| margin: 0; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| body{ | ||
| background-color: #313267; | ||
| font-size: 14px; | ||
| font-family:'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; | ||
| width: 100vw; | ||
| height: calc(100vh - 20px); | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| header{ | ||
| height: 15%; | ||
| background-color:#313267 ; | ||
| } | ||
|
|
||
|
|
||
| header a{ | ||
| height: 100%; | ||
| display: block; | ||
| text-align: center; | ||
| } | ||
|
|
||
| img{ | ||
| height: inherit; | ||
| padding: 5px; | ||
| } | ||
|
|
||
| .container{ | ||
| background-color: #6ed5e7; | ||
| width: calc(95% - 5px); | ||
| margin: auto; | ||
| height: 85%; | ||
| } | ||
|
|
||
| .selector{ | ||
| padding: 10px; | ||
| font-size: 1.7em; | ||
| background-color: rgb(252, 103, 49); | ||
| color: white; | ||
| } | ||
|
|
||
| #repo-items{ | ||
| font-size: 16px; | ||
| font-family: sans-serif; | ||
| font-weight: 700; | ||
| color: #444; | ||
| padding: .6em 1.4em .5em .8em; | ||
| max-width: 100%; /* useful when width is set to anything other than 100% */ | ||
| margin: 0px auto; | ||
| border: 1px solid #aaa; | ||
| -moz-appearance: none; | ||
| -webkit-appearance: none; | ||
| background-color: #fff; | ||
| font-family:'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; | ||
| } | ||
|
|
||
| .des-con{ | ||
| display: flex; | ||
| padding: 10px; | ||
| } | ||
|
|
||
| .description, .contributers{ | ||
| width: 50%; | ||
| border: 3px rgb(223, 152, 152) solid; | ||
| margin: 5px; | ||
|
|
||
| } | ||
|
|
||
| table{ | ||
| border-spacing: 10px; | ||
| } | ||
|
|
||
| @media only screen and (max-width:550px){ | ||
| .des-con{ | ||
| flex-direction: column; | ||
| align-items: center; | ||
| } | ||
| .description, .contributers{ | ||
| width: 90%; | ||
| } | ||
| .selector{ | ||
| text-align: center; | ||
| } | ||
| #repo-items{ | ||
| margin-top: 10px; | ||
| } | ||
| } |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.