diff options
author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2020-12-03 09:32:13 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2020-12-03 09:32:13 +0700 |
commit | 8644699f4d2fce12a41289f9627bc45be9dd1965 (patch) | |
tree | d31190ac36d10e297eeab0f6e7a70dc24395695d /usth/ICT3.2/prac/2 | |
parent | 82048ad9e3e4a96a38c8fa6a529798f40e33acb1 (diff) | |
download | cp-8644699f4d2fce12a41289f9627bc45be9dd1965.tar.gz |
[usth/ICT3.2] Develop web applications
Diffstat (limited to 'usth/ICT3.2/prac/2')
-rw-r--r-- | usth/ICT3.2/prac/2/1.js | 9 | ||||
-rw-r--r-- | usth/ICT3.2/prac/2/10.html | 49 | ||||
-rw-r--r-- | usth/ICT3.2/prac/2/11.html | 55 | ||||
-rw-r--r-- | usth/ICT3.2/prac/2/2.js | 5 | ||||
-rw-r--r-- | usth/ICT3.2/prac/2/3.js | 5 | ||||
-rw-r--r-- | usth/ICT3.2/prac/2/4.js | 2 | ||||
-rw-r--r-- | usth/ICT3.2/prac/2/5.js | 2 | ||||
-rw-r--r-- | usth/ICT3.2/prac/2/6.js | 11 | ||||
-rw-r--r-- | usth/ICT3.2/prac/2/7.js | 1 | ||||
-rw-r--r-- | usth/ICT3.2/prac/2/8.js | 11 | ||||
-rw-r--r-- | usth/ICT3.2/prac/2/9.js | 9 | ||||
-rw-r--r-- | usth/ICT3.2/prac/2/labwork.pdf | bin | 0 -> 1400060 bytes |
12 files changed, 159 insertions, 0 deletions
diff --git a/usth/ICT3.2/prac/2/1.js b/usth/ICT3.2/prac/2/1.js new file mode 100644 index 0000000..ecc78f2 --- /dev/null +++ b/usth/ICT3.2/prac/2/1.js @@ -0,0 +1,9 @@ +const DAYS = ['Monday', 'Tuesday', 'Wednesday', + 'Thursday', 'Friday', 'Saturday', 'Sunday']; +const NOW = new Date(); +const HOUR24 = NOW.getHours(); +const HOUR12 = HOUR24 % 12; +const PERIOD = HOUR24 < 12 ? 'AM' : 'PM'; + +console.log(`Today is: ${DAYS[NOW.getDay()-1]}`); +console.log(`Current time is: ${HOUR12} ${PERIOD}: ${NOW.getMinutes()}: ${NOW.getSeconds()}`) diff --git a/usth/ICT3.2/prac/2/10.html b/usth/ICT3.2/prac/2/10.html new file mode 100644 index 0000000..d092b48 --- /dev/null +++ b/usth/ICT3.2/prac/2/10.html @@ -0,0 +1,49 @@ +<!DOCTYPE html> +<style> +h1 { text-align: center } +form { + display: table; + margin: 0 auto; +} +p { display: table-row } +.cell { + display: table-cell; + margin: 0.2em 0; +} +</style> + +<script> +function check() { + const PW = document.getElementById('pw').value; + const PW2 = document.getElementById('pw2').value; + if (PW != PW2) + alert('Your password and confirmation password do not match!'); +} +</script> + +<html> +<body> + <h1>Sign Up</h1> + <form> + <p> + <label class=cell for=user>Username: </label> + <input class=cell type=text id=user> + </p> + <p> + <label class=cell for=pw>Password: </label> + <input class=cell type=password id=pw> + </p> + <p> + <label class=cell for=pw2>Re-type Password: </label> + <input class=cell type=password id=pw2> + </p> + <p> + <span class=cell></span> + <span class=cell> + <input type=reset> + <input type=button onclick='check()' value=Submit> + </span> + </p> + </form> +</body> +</html> diff --git a/usth/ICT3.2/prac/2/11.html b/usth/ICT3.2/prac/2/11.html new file mode 100644 index 0000000..51c0922 --- /dev/null +++ b/usth/ICT3.2/prac/2/11.html @@ -0,0 +1,55 @@ +<!DOCTYPE html> +<style> +h1 { text-align: center } +form { + display: table; + margin: 0 auto; +} +p { display: table-row } +.cell { + display: table-cell; + margin: 0.2em 0; +} +</style> + +<script> +function get() { + return [document.getElementById('1st').value, + document.getElementById('2nd').value]; +} + +function mul() { + document.getElementById('result').innerHTML = ( + (x, y) => x * y)(...get()); +} + +function div() { + document.getElementById('result').innerHTML = ( + (x, y) => x / y)(...get()); +} +</script> + +<html> +<body> + <form> + <p> + <label class=cell for=1st>1st Number: </label> + <input class=cell type=text id=1st> + </p> + <p> + <label class=cell for=2nd>2nd Number: </label> + <input class=cell type=text id=2nd> + </p> + <p> + <span class=cell></span> + <span class=cell> + <input type=button onclick='mul()' value=Multiply> + <input type=button onclick='div()' value=Divide> + </span> + <p> + <span class=cell>The Result is: </span> + <span id=result></span> + </p> + </form> +</body> +</html> diff --git a/usth/ICT3.2/prac/2/2.js b/usth/ICT3.2/prac/2/2.js new file mode 100644 index 0000000..97b49ba --- /dev/null +++ b/usth/ICT3.2/prac/2/2.js @@ -0,0 +1,5 @@ +const C = 'Temperature in Celsius: '; +const F = 'Temperature in Fahrenheit: '; + +alert(F + (prompt(C) * 1.8 + 32)); +alert(C + ((prompt(F) - 32) / 1.8)); diff --git a/usth/ICT3.2/prac/2/3.js b/usth/ICT3.2/prac/2/3.js new file mode 100644 index 0000000..45bd66e --- /dev/null +++ b/usth/ICT3.2/prac/2/3.js @@ -0,0 +1,5 @@ +const WEIGHT = Math.trunc(Math.random() * 10); +const GUESS = Math.trunc(Number( + prompt('Guess the weight of the marrow (1-10)'))); + +alert(GUESS == WEIGHT ? 'Good Work' : 'Not Matched'); diff --git a/usth/ICT3.2/prac/2/4.js b/usth/ICT3.2/prac/2/4.js new file mode 100644 index 0000000..25c2a17 --- /dev/null +++ b/usth/ICT3.2/prac/2/4.js @@ -0,0 +1,2 @@ +const S = prompt('Enter five space-separated numbers'); +alert(`The largest is ${Math.max(...S.split(' ').map(Number))}.`); diff --git a/usth/ICT3.2/prac/2/5.js b/usth/ICT3.2/prac/2/5.js new file mode 100644 index 0000000..ee502b7 --- /dev/null +++ b/usth/ICT3.2/prac/2/5.js @@ -0,0 +1,2 @@ +for (let i = 1; i < 16; ++i) + console.log(i % 2 ? `${i} is odd` : `${i} is even`); diff --git a/usth/ICT3.2/prac/2/6.js b/usth/ICT3.2/prac/2/6.js new file mode 100644 index 0000000..52cb82a --- /dev/null +++ b/usth/ICT3.2/prac/2/6.js @@ -0,0 +1,11 @@ +const A039943 = [0, 1, 4, 16, 20, 37, 42, 58, 89, 145]; // OEIS + +for (i = j = 1; i < 11; ++j) { + for (k = j; + !A039943.includes(k); + k = k.toString().split('').map(n => n*n).reduce((m, n) => m+n)); + if (k == 1) { + console.log(j); + i++; + } +} diff --git a/usth/ICT3.2/prac/2/7.js b/usth/ICT3.2/prac/2/7.js new file mode 100644 index 0000000..e268937 --- /dev/null +++ b/usth/ICT3.2/prac/2/7.js @@ -0,0 +1 @@ +alert(`Output: ${prompt('Input:').split('').reverse().join('')}`); diff --git a/usth/ICT3.2/prac/2/8.js b/usth/ICT3.2/prac/2/8.js new file mode 100644 index 0000000..07a4042 --- /dev/null +++ b/usth/ICT3.2/prac/2/8.js @@ -0,0 +1,11 @@ +function isPrime(n) { + if (n < 2 || n != Math.trunc(n)) + return false; + for (let i = 2; i * i <= n; ++i) + if (n % i == 0) + return false; + return true; +} + +if (!module.parent) + console.log(isPrime(Number(process.argv[2])) ? 'prime' : 'no prime'); diff --git a/usth/ICT3.2/prac/2/9.js b/usth/ICT3.2/prac/2/9.js new file mode 100644 index 0000000..628b9b4 --- /dev/null +++ b/usth/ICT3.2/prac/2/9.js @@ -0,0 +1,9 @@ +function second(a) { + let b = [...a].sort(); + return [b[1], b[b.length-2]]; +} + +if (!module.parent) { + let [min, max] = second(process.argv.slice(2)); + console.log(`${min} and ${max}`); +} diff --git a/usth/ICT3.2/prac/2/labwork.pdf b/usth/ICT3.2/prac/2/labwork.pdf new file mode 100644 index 0000000..f8d8ece --- /dev/null +++ b/usth/ICT3.2/prac/2/labwork.pdf Binary files differ |