Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LukeSkyRunner/bdccf2554709ff4861034edee1e1c941 to your computer and use it in GitHub Desktop.
Save LukeSkyRunner/bdccf2554709ff4861034edee1e1c941 to your computer and use it in GitHub Desktop.
Javascript Boolean and Condition Practice
//Define two string variables and compare them so you can print out which one has more characters, or they have an equal number of characters
const str1 = "Lisbon", str2 = "London"
if (str1.length > str2.length) {
console.log (str1)
}
else if (str1.length < str2.length) {
console.log (str2)
}
else {
console.log ("Egual number of characters")
}
//Given the word, check if it exists in the given sentence and print out if it does or it doesn’t:
let word = "web";
let sentence = "I enrolled Ironhack because I love web development.";
if (sentence.includes(word)){
console.log ("truthy")
}
else {
console.log ("falsy")
}
//Given the number, print if the number is odd or even:
let num = 219
let modulo = (num % 2)
if (modulo>0) {
console.log ("Even")
}
else {
console.log ("Odd")
}
//Given the year, print out the century:
// 2019; // => 21
let year = 2019
let century = year / 100
console.log (century+1)
// 111; // => 2
let year2 = 111
let century2 = year2 / 100
console.log (century2+1)
// 44; // => 1
let year3 = 44
let century3 = year3 / 100
console.log (century3+1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment