|
@@ -0,0 +1,117 @@
|
|
|
+//assign: evaluation
|
|
|
+var a = 5;
|
|
|
+var b, c;
|
|
|
+
|
|
|
+//if we delete brackets functionality is same
|
|
|
+// b = (a * 5);
|
|
|
+// b = (c = b/2);
|
|
|
+// a = 5
|
|
|
+// b = 12,5
|
|
|
+// c = 12,5
|
|
|
+
|
|
|
+//one line variant
|
|
|
+c = b = (a * 5) / 2;
|
|
|
+
|
|
|
+// forgot one semicolon!
|
|
|
+// for(let i = 0 i < 5; i++) {
|
|
|
+// console.log(i)
|
|
|
+// }
|
|
|
+// wrong usage of semicolon
|
|
|
+//let a; b = 5;
|
|
|
+//b = 5 c = b + 1;
|
|
|
+
|
|
|
+//semicolon logic errors
|
|
|
+// if(a === 5) {
|
|
|
+// console.log('FIVE!')
|
|
|
+// }else; console.log('not five(')
|
|
|
+
|
|
|
+//GET YEAR TASK:
|
|
|
+function getAge(age, currentYear = new Date().getFullYear()) {
|
|
|
+ try {
|
|
|
+ age = Math.trunc(Number(age))
|
|
|
+ if(!age || isNaN(age) || age > 200 || age < 0) {
|
|
|
+ throw e
|
|
|
+ } else {
|
|
|
+ currentYear = currentYear - age
|
|
|
+ return [currentYear, currentYear-1]
|
|
|
+ }
|
|
|
+ } catch(e) {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+let year = getAge(prompt("input your age",""))
|
|
|
+if(year) {
|
|
|
+ alert(`Looks like you've been born in ${year[0]} or ${year[1]}`)
|
|
|
+} else {
|
|
|
+ alert('whoops, looks like invalid input value has been given!')
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//GET TEMPERATURE TASK:
|
|
|
+try {
|
|
|
+ let grad = Number(prompt("Input temperature",""))
|
|
|
+ let sys = prompt(`
|
|
|
+ Type:
|
|
|
+ F - to translate to Fahrenheit
|
|
|
+ C - to translate to Celsius
|
|
|
+ `)
|
|
|
+ let res = getTemperature(grad, sys)
|
|
|
+ if(res) {
|
|
|
+ alert(`${grad}${sys.toLowerCase() === 'c'? '°F':'°C'} = ${res}${sys.toLowerCase() === 'c'? '°C':'°F'}`)
|
|
|
+ } else {
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+} catch(e) {
|
|
|
+ alert('invalid input!')
|
|
|
+}
|
|
|
+
|
|
|
+function getTemperature(value, system="c") {
|
|
|
+ if(isNaN(Number(value))) return false
|
|
|
+
|
|
|
+ switch(system.toLowerCase()) {
|
|
|
+ case 'f':
|
|
|
+ return ((value * 9/5) + 32).toFixed(2)
|
|
|
+ case 'c':
|
|
|
+ return ((value - 32) * 5/9).toFixed(2)
|
|
|
+ default:
|
|
|
+ return false
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//divide using floor
|
|
|
+function flooredDivide(num1, num2) {
|
|
|
+ console.log(num1 / num2)
|
|
|
+ return Math.floor(num1 / num2)
|
|
|
+}
|
|
|
+
|
|
|
+//infor user if number given is odd task
|
|
|
+function oddInformer() {
|
|
|
+ let num = prompt("input a number:", "")
|
|
|
+ if(isNaN(+num) || !num) {
|
|
|
+ alert("not a number!!!")
|
|
|
+ } else {
|
|
|
+ if(num % 2 !== 0) {
|
|
|
+ alert(`${num} is odd`)
|
|
|
+ } else {
|
|
|
+ alert(`${num} is even`)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+oddInformer()
|
|
|
+
|
|
|
+//greet user using alert() and prompt()
|
|
|
+function greeting() {
|
|
|
+ let name = prompt("Hey user, what's your name")
|
|
|
+ alert(`Hello, ${name? name : 'Namless One...'}`)
|
|
|
+}
|
|
|
+greeting()
|
|
|
+
|
|
|
+//check if text contains desired words
|
|
|
+function lexis(string, word) {
|
|
|
+ if(string.indexOf(word) > 0) {
|
|
|
+ return true
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+}
|