There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
I don’t remember being taught this. If you place a backslash before a single apostrophe does it indicate that it is part of the string and not an indicator of where a string starts and stops?
Is there a way to change the variable season (in the code below) using a particular time interval, from summer to spring to fall and back to summer?
let season = ‘summer’;
if (season === ‘spring’) {
console.log(‘It’s spring! The trees are budding!’);
}
else if (season === ‘winter’) {
console.log(‘It’s winter! Everything is covered in snow.’);
}
else if (season === ‘fall’) {
console.log(‘It’s fall! Leaves are falling!’)
}
else if (season === ‘summer’) {
console.log(‘It’s sunny and warm because it’s summer!’)
}
else {
console.log(‘Invalid season.’);
}
Does anybody know what I have done wrong here. let season = ‘summer’;
if (season === ‘spring’) {
console.log(‘It’s spring! The trees are budding!’);
} else if (season === ‘winter’) {
console.log(‘It’s winter! Everything is covered in snow’);
} else {
console.log(‘Invalid season.’);
}
ONE. Why is there a backslash inside the word “It’s”?
TWO. How do I write possessive words like “It’s” in JavaScript? Every time I start typing a string, I start with the ’ single quotation mark then start typing my string. But then if a word is possessive and contains the ’ single quotation mark, it closes my string and I can’t add more single quotation marks because they force me to add 2 single quotation marks at the same time. Just impossible.
Question one is the answer to question two, by escaping (the backslash) the apostrophe, you can insert apostrophes in a string enclosed in apostrophes.
of course, the easier solution in javascript is to enclose your string in quotation marks, then you don’t need the backslash
What if I want to log the same string if either one or the other of two things are true? For example, I want to say
if {season === "fall’ || ‘autumn’) { console.log(‘It’s fall!’); }
But using the || doesn’t work, because then it just logs this even when season === ‘summer’. Or maybe I’m just using it all wrong?
Then why does it have the triple === ? I thought that that meant that we were looking for an exact match. Because ‘autumn’ isn’t the variable, it’s the (potential) value of the variable, and we’re checking if the string is, indeed, the same as the string assigned to the variable “season.”
And how would one go about trying to log the same string for both ‘autumn’ and ‘fall’ without creating a whole new “else if” statement?
it does, but that is only for season === 'fall' (the left hand side of your or (||) operator. On the right hand side of your or operator you don’t do any comparison.
on the right hand side of your or operator, you also need to check for equality.