Skip to content

Instantly share code, notes, and snippets.

View Chuloo's full-sized avatar

William Chuloo

View GitHub Profile
@Chuloo
Chuloo / string-match-method.js
Created March 27, 2019 13:09
Catch lower case
// Create a new string
const sentence = "How Do yOu feEl about chANGing the WoRLD"
// Create search expression
const regex = /[a-z]/g;
// Find matching strings
let lowerCaseLetters = sentence.match(regex)
// Display strings
// New name
const name = 'Sean Paul';
// Search term
const firstName = 'Sean';
// Verify and display name if the firstname matches the search term
if(name.startsWith(firstName)){
console.log(name)
}
// Create a string and a search item
const sentence = "the lazy brown fox just couldn't move"
const keyWord = "the"
// Verify start word
let checkFirstWord = sentence.startsWith(keyWord)
// Display result
console.log(checkFirstWord)
// Create two variables with words
const word = 'Please';
const greeting = 'Hello';
// Convert the words to lower case
const lowercaseWord = word.toLowerCase();
const lowercaseGreeting = greeting.toLowerCase();
// Compare equality and display result
console.log(lowercaseWord === lowercaseGreeting);
@Chuloo
Chuloo / string-lowercase-method.js
Created March 26, 2019 23:46
No upper case allowed here
// New password string
const password = "Tunechi4LifE"
// Convert to lower case
const convertedPassword = password.toLowerCase()
// Display lower case password
console.log(convertedPassword)
@Chuloo
Chuloo / string-length-property.js
Created March 26, 2019 23:25
Password Length
// Create new password
const password = 'p@ssword';
// Verify password length
if(password.length < 8){
console.log('Your password is weak')
}else{
console.log("Strong password selected")
}
// New string
const word = "accessibility"
// Find the length of the word
let lengthOfWord = word.length
// Display length
console.log(`${word} has ${lengthOfWord} letters in it`)
@Chuloo
Chuloo / string-method-trim.js
Created March 25, 2019 23:52
Split the excesses
const username = ' Paul ';
const password = ' p@ssw0rd ';
const trimmedUser = username.trim();
console.log(trimmedUser);
const trimmedPass = password.trim();
console.log(trimmedPass);
@Chuloo
Chuloo / string-trim-method.js
Last active March 25, 2019 23:55
Drop weight
// Sample bulky sentence
let sentence = " scotchy scotch "
// trim sentence
let trimmedSentence = sentence.trim()
// display output
console.log(trimmedSentence)
// New sentence
const sentence = 'Friday is the last day';
// Keyword to be searched for
const day = 'Friday';
// Find index of keyword
const hasDay = sentence.indexOf(day);