Ver código fonte

Finish boolean-advanced

Signed-off-by: Michael Tang <michael.h.tang@gmail.com>
Michael Tang 5 anos atrás
pai
commit
bed964cffc
3 arquivos alterados com 44 adições e 10 exclusões
  1. 25 0
      boolean-advanced.js
  2. 17 8
      boolean.js
  3. 2 2
      temp-conversion.js

+ 25 - 0
boolean-advanced.js

@@ -0,0 +1,25 @@
+let isAccountLocked = false
+let userRole = 'user'
+
+if (isAccountLocked) {
+    console.log('Is account locked')
+} else if (userRole === 'admin') {
+    console.log('Welcome admin')
+} else {
+    console.log('Welcome')
+}
+
+// Challenge area
+
+let temp = 120
+
+// it's freezing outside <= 32
+// it's hot outside 33 - 109
+// Go for it. It's pretty nice >= 110 
+if (temp > 110) {
+    console.log("It's hot outside!")
+} else if (temp  <= 32) {
+    console.log("It's freezing outside")
+} else {
+    console.log("Go for it, it's pretty nice.")
+}

+ 17 - 8
boolean.js

@@ -5,10 +5,16 @@
 // <=  - less than or equl to
 // >=  - greater than or equal to
 
-let temp = 31
-let isFreezing = temp < 32
+let temp = 180
+
+if (temp <= 32) {
+    console.log('It is freezing outside!')
+}
+
+if (temp >= 110) {
+    console.log('It is way too hot outside!')
+}
 
-console.log(isFreezing)
 
 //Challenge area
 
@@ -18,9 +24,12 @@ console.log(isFreezing)
 // Print is child value
 // Print is senior value
 
-let age = 7
-let isChild = age <= 65
-let isSenior = age >= 65
+let age = 6
+
+if (age <= 7){
+    console.log('You are eligible for child discount')
+}
 
-console.log('isChild: ' + isChild )
-console.log('isSenior: ' + isSenior)
+if (age >=65) {
+    console.log('Lucky you, you get the senior discount')
+}

+ 2 - 2
temp-conversion.js

@@ -1,5 +1,5 @@
 let fahrenheit = -50
-let celcius = (fahrenheit - 32) * (5/9)
-console.log(celcius + 'C')
+let celsius = (fahrenheit - 32) * (5/9)
+console.log(celsius + 'C')
 let kelvin = (fahrenheit + 459.67) * (5/9)
 console.log(kelvin + 'K')