/*
CS 22A
Assignment 2
Question 2
Write a function snooze that takes on parameter, day, and
returns a boolean: true if day is a weekend, false if otherwise.
If invalid argument/no argument, return false.
The parameter day may be lowercase, uppercase, or mixed.
*/
function snooze(day){
day = day || 0;
var Sat = 'Saturday';
var Sun = 'Sunday';
if (day === Sat){
return true;
} else if (day === Sat.toUpperCase()){
return true;
} else if (day === Sat.toLowerCase()){
return true;
} else if (day === Sun){
return true;
} else if (day === Sun.toUpperCase()){
return true;
} else if (day === Sun.toLowerCase()){
return true;
} else {
return false;
}
}
console.log(snooze('Monday')) // false
console.log(snooze('tuesday')) // false
console.log(snooze('SUNDAY')) // true
console.log(snooze('Saturday')) // true
console.log(snooze('October')) // false
console.log(snooze()) // false
console.log(snooze('SatUrDaY')) // true
Hi all. I'm a bit new to programming and I'm taking up the javascript class at my school at the moment. One of the questions in my assignment this week is to create a function that takes on a parameter and returns a boolean, just as described in the comments above my code.
My issue is that I do not understand how to make it so mixed-case inputs will be understood as their lowercase/uppercase counterparts. I did some googling and most results tell me to use regex, a concept we have yet to cover and I would get in trouble for doing so. Can someone shed some light as to how I can approach this?
Also, while I'm at it- can someone nudge me in the correct path for the last question of this assignment?
Your task is to define a function count that takes two parameters: word and char. The function returns the number of times the character occurs in the given word. You may assume that both parameters are lower case strings.
Again, I have googled how to approach that problem but most results tell me to use regex or arrays, concepts we have yet to cover in class and I would get in trouble for doing so. Any help would be appreciated. Thanks again!