From 46a2f9f3e04534f3b3bf70dfc9317ad9de8a1de7 Mon Sep 17 00:00:00 2001 From: fsotol69 Date: Thu, 25 Apr 2019 02:30:19 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Commit=20Exercicis=20B=C3=A0sics=20JS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- css/styles.css | 36 ++++++++++++++++++++++++++++++++++++ index.html | 27 +++++++++++++++++++++++++++ main.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 css/styles.css create mode 100644 index.html create mode 100644 main.js diff --git a/css/styles.css b/css/styles.css new file mode 100644 index 0000000..223d06e --- /dev/null +++ b/css/styles.css @@ -0,0 +1,36 @@ +.button { + font-family: Arial, Helvetica, sans-serif; + font-size: 20px; + font-weight: bold; + color: #fff; + background-color: crimson; + text-align: center; + border-radius: 10px; + width: 150px; + height: 90px; + padding: 20px; + margin: 5px; + float: left; +} + +.result { + font-family: Arial, Helvetica, sans-serif; + font-size: 20px; + font-weight: bold; + color: #fff; + background-color: crimson; + text-align: center; + border-radius: 10px; + width: 200px; + height: 50px; + padding: 20px; + margin: 5px; + float: left; +} + +.contenedor { + width: 100%; + height: 100px; + float: left; + clear: both; +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..325bb4f --- /dev/null +++ b/index.html @@ -0,0 +1,27 @@ + + + + + + + + + + Document + + +
+ +
+
+
+ +
+
+
+ +
+
+ + + diff --git a/main.js b/main.js new file mode 100644 index 0000000..0af77c7 --- /dev/null +++ b/main.js @@ -0,0 +1,43 @@ +document.getElementById('button1').addEventListener('click', function() { + exercici1(); +}); +document.getElementById('button2').addEventListener('click', function() { + exercici2(); +}); +document.getElementById('button3').addEventListener('click', function() { + exercici3(); +}); +// document.getElementById('button1').addEventListener('click', exercici1()); +// document.getElementById('button2').addEventListener('click', exercici2()); +// document.getElementById('button3').addEventListener('click', exercici3()); + +function exercici1() { + let respuesta = 'jello'.indexOf('e'); + document.getElementById('text1').innerHTML = respuesta; + console.log(respuesta); +} +// Exercici 2 +function exercici2() { + let nombre = prompt('Introduce tu nombre :'); + let apellido = prompt('Introduce tu apellido :'); + // alert(`Hola ${nombre} ${apellido}!`); + document.getElementById('text2').innerHTML = `Hola ${nombre} ${apellido}!`; +} +// Exercici 3 +function exercici3() { + let population = 1000; + let increaseTax = 0.02; + let increaseNum = 50; + let year = 1; + + while (population < 1200) { + population += population * increaseTax + 50; + console.log('population : ' + population + ' year :' + year); + year++; + } + if (year > 2) { + document.getElementById('text3').innerHTML = `Necessita ${year - 1} anys.`; + } else { + document.getElementById('text3').innerHTML = `Necessita ${year - 1} any.`; + } +} From 208f965ac36bff9aedfa927bb149651a6ab02683 Mon Sep 17 00:00:00 2001 From: Ferran Soto Date: Thu, 25 Apr 2019 10:27:30 +0200 Subject: [PATCH 2/2] Ejercicios js 1, 2, 3, 4 --- index.html | 4 ++++ main.js | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/index.html b/index.html index 325bb4f..3d550cc 100644 --- a/index.html +++ b/index.html @@ -22,6 +22,10 @@
+
+ +
+
diff --git a/main.js b/main.js index 0af77c7..a2c229a 100644 --- a/main.js +++ b/main.js @@ -25,6 +25,17 @@ function exercici2() { } // Exercici 3 function exercici3() { + let cadena = prompt('Introduce una cadena de texto :'); + let array = "a b c d f g h i j k l m n ñ o p q r s t u v w x y z A B C D E F G H Y J K L M N Ñ O P Q R S T U V W X Y Z".split(' '); + let muestra = array[Math.floor(Math.random() * array.length)]; + if(cadena.includes(muestra)){ + document.getElementById('text3').innerHTML = `El carácter ${muestra} SÍ está.`; + } else { + document.getElementById('text3').innerHTML = `El carácter ${muestra} NO está.`; + } +} +// Exercici 4 +function exercici4() { let population = 1000; let increaseTax = 0.02; let increaseNum = 50;