From dfae89244d2d56860fe02f78bc5f2b924c85038e Mon Sep 17 00:00:00 2001 From: lazcanogaston Date: Fri, 19 Oct 2018 19:18:06 -0300 Subject: [PATCH 1/4] exercise 1 --- 01-JS-DOM-APIs/css/styles1.css | 18 ++++++++++++++++++ 01-JS-DOM-APIs/index.html | 21 +++++++++++++++++++++ 01-JS-DOM-APIs/js/functions1.js | 9 +++++++++ 3 files changed, 48 insertions(+) create mode 100644 01-JS-DOM-APIs/css/styles1.css create mode 100644 01-JS-DOM-APIs/index.html create mode 100644 01-JS-DOM-APIs/js/functions1.js diff --git a/01-JS-DOM-APIs/css/styles1.css b/01-JS-DOM-APIs/css/styles1.css new file mode 100644 index 00000000..929a9f4a --- /dev/null +++ b/01-JS-DOM-APIs/css/styles1.css @@ -0,0 +1,18 @@ +*{ + text-align: center; +} + +#hidden{ + opacity: 0; +} + +#hidden.loaded{ + opacity: 1; +} + + +footer{ + position: absolute; + width: 100%; + bottom: 0; +} diff --git a/01-JS-DOM-APIs/index.html b/01-JS-DOM-APIs/index.html new file mode 100644 index 00000000..ee1ef6a9 --- /dev/null +++ b/01-JS-DOM-APIs/index.html @@ -0,0 +1,21 @@ + + + + + + + + + topic 1 + + +
+

TOPIC 1

+
+

Hello world!

+
+

Gaston Lazcano 2018

+
+ + + \ No newline at end of file diff --git a/01-JS-DOM-APIs/js/functions1.js b/01-JS-DOM-APIs/js/functions1.js new file mode 100644 index 00000000..8e151784 --- /dev/null +++ b/01-JS-DOM-APIs/js/functions1.js @@ -0,0 +1,9 @@ +function showSection(id){ + var element = document.getElementById(id); + + element.classList.add("loaded"); + }; + + window.addEventListener("load", function(){showSection("hidden")}); + + \ No newline at end of file From 1066c03002646b49e1adce3aed98db9726feda8c Mon Sep 17 00:00:00 2001 From: lazcanogaston Date: Fri, 19 Oct 2018 19:54:54 -0300 Subject: [PATCH 2/4] exercise 2 --- 01-JS-DOM-APIs/index.html | 1 + 01-JS-DOM-APIs/js/functions1.js | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/01-JS-DOM-APIs/index.html b/01-JS-DOM-APIs/index.html index ee1ef6a9..ff912999 100644 --- a/01-JS-DOM-APIs/index.html +++ b/01-JS-DOM-APIs/index.html @@ -14,6 +14,7 @@

Hello world!

+

Gaston Lazcano 2018

diff --git a/01-JS-DOM-APIs/js/functions1.js b/01-JS-DOM-APIs/js/functions1.js index 8e151784..f2dba590 100644 --- a/01-JS-DOM-APIs/js/functions1.js +++ b/01-JS-DOM-APIs/js/functions1.js @@ -1,3 +1,5 @@ +//exercise 1 + function showSection(id){ var element = document.getElementById(id); @@ -6,4 +8,8 @@ function showSection(id){ window.addEventListener("load", function(){showSection("hidden")}); - \ No newline at end of file + //exercise 2 + +function displayAlert(){ + window.alert("WELCOME!"); +} From 6f4692b7d236822e4a6b4582a45b21363f16fad8 Mon Sep 17 00:00:00 2001 From: lazcanogaston Date: Mon, 22 Oct 2018 11:01:18 -0300 Subject: [PATCH 3/4] exercise 3 --- 01-JS-DOM-APIs/css/styles1.css | 8 ++++ 01-JS-DOM-APIs/index.html | 10 ++++- 01-JS-DOM-APIs/js/functions1.js | 73 +++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) diff --git a/01-JS-DOM-APIs/css/styles1.css b/01-JS-DOM-APIs/css/styles1.css index 929a9f4a..e4c39853 100644 --- a/01-JS-DOM-APIs/css/styles1.css +++ b/01-JS-DOM-APIs/css/styles1.css @@ -16,3 +16,11 @@ footer{ width: 100%; bottom: 0; } + +#joke.error{ + background-color: red; +} + +#joke{ + background-color: white; +} \ No newline at end of file diff --git a/01-JS-DOM-APIs/index.html b/01-JS-DOM-APIs/index.html index ff912999..d51b8b84 100644 --- a/01-JS-DOM-APIs/index.html +++ b/01-JS-DOM-APIs/index.html @@ -5,7 +5,7 @@ - + topic 1 @@ -15,8 +15,16 @@

Hello world!

+ +
+ +
+ +
+

Gaston Lazcano 2018

+ \ No newline at end of file diff --git a/01-JS-DOM-APIs/js/functions1.js b/01-JS-DOM-APIs/js/functions1.js index f2dba590..a973db94 100644 --- a/01-JS-DOM-APIs/js/functions1.js +++ b/01-JS-DOM-APIs/js/functions1.js @@ -13,3 +13,76 @@ function showSection(id){ function displayAlert(){ window.alert("WELCOME!"); } + +//exercise 3 + + +document.getElementById("btn").addEventListener("click", function(){readApi()}); +/* +function readApi(){ + + fetch('http://api.icndb.com/jokes/random') //connection returns a promise + .then(function(response) { + console.log(response); + return response.json(); //return as a json object + }) + .then(function(myJson) { //i can choose any name to the parameter + console.log(myJson); + //var obj = JSON.parse(myJson); + document.getElementById("joke").innerHTML=myJson.value.joke; + + }); + +} +*/ + + + +function readApi(){ + var request = new XMLHttpRequest(); + request.open("GET", "http://api.icndb.com/jokes/random", true); + request.send(); + + request.onreadystatechange = function() { + if (this.readyState === 4 && this.status === 200) { + let obj = JSON.parse(request.responseText); //the xhttp.responseText returns a text in JSON format and JSON.parse create an object, + document.getElementById("joke").innerHTML = obj.value.joke; + document.getElementById("joke").classList.remove("error"); //if the conection failed and then, it returns, the background-color:red, disappear + } + }; + request.onerror = function() { + console.log('There was an error!'); + + document.getElementById("joke").innerHTML = 'there was an error'; + document.getElementById("joke").classList.add("error"); + }; + +} + + +//reusable function to perform ajax calls + +//promise: it is an object that represents the termination or eventual failure of an asynchronous operation. + + function ajaxCall(url, method){ + var prom= new Promise(resolve, reject); + var request = new XMLHttpRequest(); + request.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + var response = request.responseText; + resolve(request.response); // If successful, resolve the promise by passing back the request response + } + else { + reject(request.statusText); + } + + }; + request.onerror = function() { + console.log('There was an error!'); + }; + request.open(method, url, true); + request.send(); + return prom; + } + + From 929e696adf9ff38248c98cf4295d38cf21f03e6b Mon Sep 17 00:00:00 2001 From: lazcanogaston Date: Tue, 23 Oct 2018 19:58:26 -0300 Subject: [PATCH 4/4] exercise 4 modified and ejercise 5 --- 01-JS-DOM-APIs/css/normalize.css | 341 +++++++++++++++++++++++++++++++ 01-JS-DOM-APIs/css/styles1.css | 66 +++++- 01-JS-DOM-APIs/index.html | 41 +++- 01-JS-DOM-APIs/js/functions1.js | 156 ++++++++++++-- 4 files changed, 568 insertions(+), 36 deletions(-) create mode 100644 01-JS-DOM-APIs/css/normalize.css diff --git a/01-JS-DOM-APIs/css/normalize.css b/01-JS-DOM-APIs/css/normalize.css new file mode 100644 index 00000000..aba238fe --- /dev/null +++ b/01-JS-DOM-APIs/css/normalize.css @@ -0,0 +1,341 @@ +/*! normalize.css v8.0.0 | MIT License | github.com/necolas/normalize.css */ + +/* Document + ========================================================================== */ + +/** + * 1. Correct the line height in all browsers. + * 2. Prevent adjustments of font size after orientation changes in iOS. + */ + + html { + line-height: 1.15; /* 1 */ + -webkit-text-size-adjust: 100%; /* 2 */ + } + + /* Sections + ========================================================================== */ + + /** + * Remove the margin in all browsers. + */ + + body { + margin: 0; + } + + /** + * Correct the font size and margin on `h1` elements within `section` and + * `article` contexts in Chrome, Firefox, and Safari. + */ + + h1 { + font-size: 2em; + margin: 0.67em 0; + } + + /* Grouping content + ========================================================================== */ + + /** + * 1. Add the correct box sizing in Firefox. + * 2. Show the overflow in Edge and IE. + */ + + hr { + box-sizing: content-box; /* 1 */ + height: 0; /* 1 */ + overflow: visible; /* 2 */ + } + + /** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + + pre { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ + } + + /* Text-level semantics + ========================================================================== */ + + /** + * Remove the gray background on active links in IE 10. + */ + + a { + background-color: transparent; + } + + /** + * 1. Remove the bottom border in Chrome 57- + * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari. + */ + + abbr[title] { + border-bottom: none; /* 1 */ + text-decoration: underline; /* 2 */ + text-decoration: underline dotted; /* 2 */ + } + + /** + * Add the correct font weight in Chrome, Edge, and Safari. + */ + + b, + strong { + font-weight: bolder; + } + + /** + * 1. Correct the inheritance and scaling of font size in all browsers. + * 2. Correct the odd `em` font sizing in all browsers. + */ + + code, + kbd, + samp { + font-family: monospace, monospace; /* 1 */ + font-size: 1em; /* 2 */ + } + + /** + * Add the correct font size in all browsers. + */ + + small { + font-size: 80%; + } + + /** + * Prevent `sub` and `sup` elements from affecting the line height in + * all browsers. + */ + + sub, + sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; + } + + sub { + bottom: -0.25em; + } + + sup { + top: -0.5em; + } + + /* Embedded content + ========================================================================== */ + + /** + * Remove the border on images inside links in IE 10. + */ + + img { + border-style: none; + } + + /* Forms + ========================================================================== */ + + /** + * 1. Change the font styles in all browsers. + * 2. Remove the margin in Firefox and Safari. + */ + + button, + input, + optgroup, + select, + textarea { + font-family: inherit; /* 1 */ + font-size: 100%; /* 1 */ + line-height: 1.15; /* 1 */ + margin: 0; /* 2 */ + } + + /** + * Show the overflow in IE. + * 1. Show the overflow in Edge. + */ + + button, + input { /* 1 */ + overflow: visible; + } + + /** + * Remove the inheritance of text transform in Edge, Firefox, and IE. + * 1. Remove the inheritance of text transform in Firefox. + */ + + button, + select { /* 1 */ + text-transform: none; + } + + /** + * Correct the inability to style clickable types in iOS and Safari. + */ + + button, + [type="button"], + [type="reset"], + [type="submit"] { + -webkit-appearance: button; + } + + /** + * Remove the inner border and padding in Firefox. + */ + + button::-moz-focus-inner, + [type="button"]::-moz-focus-inner, + [type="reset"]::-moz-focus-inner, + [type="submit"]::-moz-focus-inner { + border-style: none; + padding: 0; + } + + /** + * Restore the focus styles unset by the previous rule. + */ + + button:-moz-focusring, + [type="button"]:-moz-focusring, + [type="reset"]:-moz-focusring, + [type="submit"]:-moz-focusring { + outline: 1px dotted ButtonText; + } + + /** + * Correct the padding in Firefox. + */ + + fieldset { + padding: 0.35em 0.75em 0.625em; + } + + /** + * 1. Correct the text wrapping in Edge and IE. + * 2. Correct the color inheritance from `fieldset` elements in IE. + * 3. Remove the padding so developers are not caught out when they zero out + * `fieldset` elements in all browsers. + */ + + legend { + box-sizing: border-box; /* 1 */ + color: inherit; /* 2 */ + display: table; /* 1 */ + max-width: 100%; /* 1 */ + padding: 0; /* 3 */ + white-space: normal; /* 1 */ + } + + /** + * Add the correct vertical alignment in Chrome, Firefox, and Opera. + */ + + progress { + vertical-align: baseline; + } + + /** + * Remove the default vertical scrollbar in IE 10+. + */ + + textarea { + overflow: auto; + } + + /** + * 1. Add the correct box sizing in IE 10. + * 2. Remove the padding in IE 10. + */ + + [type="checkbox"], + [type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ + } + + /** + * Correct the cursor style of increment and decrement buttons in Chrome. + */ + + [type="number"]::-webkit-inner-spin-button, + [type="number"]::-webkit-outer-spin-button { + height: auto; + } + + /** + * 1. Correct the odd appearance in Chrome and Safari. + * 2. Correct the outline style in Safari. + */ + + [type="search"] { + -webkit-appearance: textfield; /* 1 */ + outline-offset: -2px; /* 2 */ + } + + /** + * Remove the inner padding in Chrome and Safari on macOS. + */ + + [type="search"]::-webkit-search-decoration { + -webkit-appearance: none; + } + + /** + * 1. Correct the inability to style clickable types in iOS and Safari. + * 2. Change font properties to `inherit` in Safari. + */ + + ::-webkit-file-upload-button { + -webkit-appearance: button; /* 1 */ + font: inherit; /* 2 */ + } + + /* Interactive + ========================================================================== */ + + /* + * Add the correct display in Edge, IE 10+, and Firefox. + */ + + details { + display: block; + } + + /* + * Add the correct display in all browsers. + */ + + summary { + display: list-item; + } + + /* Misc + ========================================================================== */ + + /** + * Add the correct display in IE 10+. + */ + + template { + display: none; + } + + /** + * Add the correct display in IE 10. + */ + + [hidden] { + display: none; + } \ No newline at end of file diff --git a/01-JS-DOM-APIs/css/styles1.css b/01-JS-DOM-APIs/css/styles1.css index e4c39853..1549e431 100644 --- a/01-JS-DOM-APIs/css/styles1.css +++ b/01-JS-DOM-APIs/css/styles1.css @@ -1,7 +1,7 @@ -*{ - text-align: center; -} +html{ + background-color: bisque; +} #hidden{ opacity: 0; } @@ -10,17 +10,65 @@ opacity: 1; } - +h1{ + width: 100%; + text-align: center; +} footer{ - position: absolute; + display: inline-block; + text-align: center; width: 100%; - bottom: 0; + bottom: 0%; } -#joke.error{ + +section#joke.error{ background-color: red; } -#joke{ - background-color: white; +section#joke{ + background-color: bisque; + margin-top:5%; +} + +section.wrapper { + margin-top: 2%; + float: left; + width:100%; +} +section.row{ + display: flex; +} +.wrapper section.column-two-third{ + margin-top: 5%; + top: 0%; + width: 66%; + text-align: center; +} +.wrapper aside.column-one-third{ + margin-top: 5%; + width: 33%; + text-align: left; +} + +.button{ + padding: 1%; + margin-top: 5%; + +} + +section#table{ + position: relative; + margin-left: 45%; + +} + +table{ + border: 1px solid black; +} +tr{ + border: 1px solid black; +} +td{ + border: 1px solid black; } \ No newline at end of file diff --git a/01-JS-DOM-APIs/index.html b/01-JS-DOM-APIs/index.html index d51b8b84..f6d27d18 100644 --- a/01-JS-DOM-APIs/index.html +++ b/01-JS-DOM-APIs/index.html @@ -5,26 +5,49 @@ + topic 1

TOPIC 1

-
-

Hello world!

-
- +
+
+
+

Hello world!

+
+ + + +
+ + +
+ +
+
+ +
+
+ + -
- -
-
+

Gaston Lazcano 2018

- \ No newline at end of file + + + diff --git a/01-JS-DOM-APIs/js/functions1.js b/01-JS-DOM-APIs/js/functions1.js index a973db94..9a15f4c2 100644 --- a/01-JS-DOM-APIs/js/functions1.js +++ b/01-JS-DOM-APIs/js/functions1.js @@ -41,7 +41,7 @@ function readApi(){ function readApi(){ var request = new XMLHttpRequest(); request.open("GET", "http://api.icndb.com/jokes/random", true); - request.send(); + request.onreadystatechange = function() { if (this.readyState === 4 && this.status === 200) { @@ -56,7 +56,7 @@ function readApi(){ document.getElementById("joke").innerHTML = 'there was an error'; document.getElementById("joke").classList.add("error"); }; - + request.send(); } @@ -64,25 +64,145 @@ function readApi(){ //promise: it is an object that represents the termination or eventual failure of an asynchronous operation. - function ajaxCall(url, method){ - var prom= new Promise(resolve, reject); - var request = new XMLHttpRequest(); - request.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - var response = request.responseText; - resolve(request.response); // If successful, resolve the promise by passing back the request response - } - else { - reject(request.statusText); - } + function ajaxFunction(config) { + + return new Promise(function(resolve, reject) { + + var request = new XMLHttpRequest(); + request.open(config.method, config.url, true); - }; + request.onreadystatechange = function() { + if(request.readyState === 4){ + if (request.status === 200) { + // If successful, resolve the promise by passing back the request response + resolve(request.responseText); + + } else { + // If it fails, reject the promise with a error message + + reject(request.statusText); + } + } + }; + request.onerror = function() { + // in case the entire request fails. + // This is probably a network error, so reject the promise + + reject(Error('There was a network error.')); + + }; + // Send the request + request.send(); + }); +} + + + + + //exercise 4 without AJAX REUSABLE FUNCTION + +/* + +function readApiParameters(){ + var q = searchRepo().value; //it receive the type of the repo + var request = new XMLHttpRequest(); + var config={}; + config.url='https://api.github.com/search/repositories?q=' + q; + config.method='GET'; + request.open(config.method, config.url , true); + + + request.onreadystatechange = function() { + if (this.readyState === 4 && this.status === 200) { + let obj = JSON.parse(request.responseText); //the xhttp.responseText returns a text in JSON format and JSON.parse create an object, + document.getElementById("repositories").innerHTML =""; + obj.items.forEach(element => { + console.log(element) + document.getElementById("repositories").innerHTML += "
  • " + "" + 'https://github.com/' +element.full_name + "" + "
  • " + }); + }; + } request.onerror = function() { console.log('There was an error!'); }; - request.open(method, url, true); - request.send(); - return prom; - } + request.send(); +} +*/ + +//EXERCISE 4 using AJAX REUSABLE FUNCTION +function configUrl() +{ var q= searchRepo().value; + var config={}; + config.url='https://api.github.com/search/repositories?q=' + q; + config.method='GET'; + return config; +} + +function readApiParameters(){ + var config=configUrl(); + console.log(config); + var promise=ajaxFunction(config) + .then(resolve => printResolve(resolve)) + .catch(reject => console.log('error')); + console.log("fin"); +} + +function printResolve(resolve){ + let obj = JSON.parse(resolve); + document.getElementById("repositories").innerHTML =""; + obj.items.forEach(element => { + document.getElementById("repositories").innerHTML += "
  • " + "" + 'https://github.com/' +element["full_name"] + "" + "
  • " + }) +} + + +function searchRepo(){ + var search= document.getElementById("input"); + return search; +} + + + +//exercise 5 + +function createMatrix(r,c){ + var colArray= new Array(c); + for(let x=0; x < c; x++) + { + colArray[x] = new Array(r); + } + + for(let x=0; x