Selaa lähdekoodia

Finish string-methods

Signed-off-by: Michael Tang <michael.h.tang@gmail.com>
Michael Tang 5 vuotta sitten
vanhempi
commit
a2cd1bb1ce
1 muutettua tiedostoa jossa 28 lisäystä ja 0 poistoa
  1. 28 0
      string-methods.js

+ 28 - 0
string-methods.js

@@ -0,0 +1,28 @@
+let name = ' Andrew Mead  '
+
+// Length property
+console.log(name.length) 
+
+// Convert to uppercase
+console.log(name.toUpperCase())
+
+// Convert to lowercase
+console.log(name.toLowerCase())
+
+// Includes method
+let password = 'abc123password098'
+console.log(password.includes('password'))
+
+// Trim
+console.log(name.trim())
+
+// Challenge area
+
+// isValidPassword
+// length is more than 8 - and it doesn't contain the word password 
+let isValidPassword = function(pass) {
+    return pass.length > 8 && !pass.includes('password')
+}
+console.log(isValidPassword('asdfp'))
+console.log(isValidPassword('abc123!@##$%'))
+console.log(isValidPassword('asdfpasswordsdfdffdfdfd22'))