forked from HackYourFuture/JavaScript3
-
Notifications
You must be signed in to change notification settings - Fork 2
Week2 masoud #3
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
Week2 masoud #3
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7bf4869
Ex1
massam89 5c5c993
Ex2
massam89 b8df810
Ex3
massam89 7652c8d
Start project week2
massam89 a579b86
change folder
massam89 39e4a5f
Fixed Ex3
massam89 30c5a23
Fixed Ex3 again :D
massam89 5d733ac
Fnished project week2
massam89 335aa1a
Fixed image problem in project week 2
massam89 63a5404
remove some comments and change input to change
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,17 @@ | ||
| const getAnonName = firstName => { | ||
| return new Promise((resolves, rejects) => { | ||
| if (firstName) { | ||
| resolves(`${firstName} S`); | ||
| } else { | ||
| rejects(new Error("You didn't pass in a first name!")); | ||
| } | ||
| }) | ||
| }; | ||
|
|
||
| const firstName = 'Mas'; | ||
| getAnonName(firstName).then(response => { | ||
| console.log(response); | ||
| }) | ||
| .catch(error => { | ||
| console.log(error); | ||
| }) |
18 changes: 18 additions & 0 deletions
18
Week2/homework/masoud/js-exercises/Ex2-isItBiggerThan10.js
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,18 @@ | ||
| const checkDoubleDigits = number => { | ||
| return new Promise((resolves, rejects) => { | ||
| if (number >= 10) { | ||
| resolves('The number is bigger than or equal 10!'); | ||
| } else { | ||
| rejects(new Error('Error! The number is smaller than 10...')); | ||
| } | ||
| }) | ||
| }; | ||
|
|
||
| const number = 10; | ||
|
|
||
| checkDoubleDigits(number).then(response => { | ||
| console.log(response); | ||
| }) | ||
| .catch(error => { | ||
| console.log(error); | ||
| }) |
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,15 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>pokemon</title> | ||
| </head> | ||
|
|
||
| <body> | ||
|
|
||
| <script src="script.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,71 @@ | ||
| //Calling main function after window load | ||
| window.onload = main; | ||
|
|
||
| //Define main function | ||
| function main() { | ||
| //Define button element | ||
| const btn = document.createElement('button'); | ||
| btn.textContent = 'start'; | ||
| btn.style.display = 'block'; | ||
| document.body.appendChild(btn); | ||
|
|
||
| // Define select element | ||
| const select = document.createElement('select'); | ||
| select.style.display = 'block'; | ||
| document.body.appendChild(select); | ||
|
|
||
| //Define image | ||
| const img = document.createElement('img'); | ||
|
|
||
| //When button is clicked | ||
| btn.addEventListener('click', () => { | ||
| const url = `https://pokeapi.co/api/v2/pokemon/?limit=20&offset=20`;//Define API URL | ||
| fetchData(url, select, img); // Get data from API and insert to DOM | ||
| }); | ||
| } | ||
|
|
||
| // Add data to DOM | ||
| function addPokemonToDOM(data, select, img) { | ||
|
|
||
| //Add list to select tag | ||
| data.results.forEach(element => { | ||
| const option = document.createElement('option'); | ||
| option.value = element.name; | ||
| option.textContent = element.name; | ||
| select.appendChild(option); | ||
| }); | ||
|
|
||
| //User selection | ||
| select.addEventListener('input', () => { | ||
|
massam89 marked this conversation as resolved.
|
||
| data.results.forEach(element => { | ||
| if (select.value == element.name) { | ||
| const imgURL = element.url; | ||
| fetch(imgURL) // second API request to get image | ||
| .then(function (response) { | ||
| return response.json(); | ||
| }) | ||
| .then(function (myJson) { | ||
| img.src = myJson.sprites.back_default; | ||
| document.body.appendChild(img); | ||
| }) | ||
| .catch(function (error) { | ||
| console.log(error); | ||
| }); | ||
| } | ||
| }) | ||
| }) | ||
| }; | ||
|
|
||
| //Get data from API by using fetch API | ||
| function fetchData(url, select, img) { | ||
| fetch(url) // First getting data | ||
| .then(function (response) { | ||
| return response.json(); | ||
| }) | ||
| .then(function (myJson) { | ||
| addPokemonToDOM(myJson, select, img); // Add data to DOM | ||
| }) | ||
| .catch(function (error) { | ||
| console.log(error); | ||
| }); | ||
| }; | ||
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,119 @@ | ||
| * { | ||
| 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); | ||
| } | ||
|
|
||
| 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.4em; | ||
| background-color: rgb(252, 103, 49); | ||
| color: white; | ||
| } | ||
|
|
||
| #repo-items{ | ||
| font-size: 12px; | ||
| 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{ | ||
| border: 2px rgb(223, 152, 152) solid; | ||
| margin: 5px; | ||
| height: 70vh; | ||
| overflow: auto; | ||
| } | ||
|
|
||
| .description { | ||
| width: 40%; | ||
| } | ||
|
|
||
| .contributers{ | ||
| width: 60%; | ||
| } | ||
|
|
||
| .contributers img{ | ||
| width: 20%; | ||
| border-radius: 50%; | ||
| } | ||
|
|
||
| .items { | ||
| display: flex; | ||
| justify-content: space-between; | ||
| padding: 5px 15px; | ||
| margin: 5px; | ||
| align-items: center; | ||
| } | ||
|
|
||
| table{ | ||
| border-spacing: 10px; | ||
| } | ||
|
|
||
| @media only screen and (max-width:550px){ | ||
| .des-con{ | ||
| flex-direction: column; | ||
| align-items: center; | ||
| } | ||
| .description, .contributers{ | ||
| width: 90%; | ||
| overflow:visible; | ||
| height: auto; | ||
| } | ||
| .selector{ | ||
| text-align: center; | ||
| } | ||
| #repo-items{ | ||
| margin-top: 10px; | ||
| } | ||
|
|
||
| body{ | ||
| width: 100%; | ||
| height: 100%; | ||
| } | ||
| } |
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.
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,17 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Hack Your Future</title> | ||
| <link rel="icon" href="img/favicon.ico" type="image/x-icon"> | ||
| <link rel="stylesheet" href="css/style.css"> | ||
| </head> | ||
|
|
||
| <body> | ||
|
|
||
| <script src="js/script.js"></script> | ||
| </body> | ||
|
|
||
| </html> |
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.