Hello!
Cannot understand what’s wrong with this code:
=====
let tool = ‘’;
tool = ‘marker’;
// Use short circuit evaluation to assign writingUtensil variable below:
let writingUtensil;
if (tool)
{
writingUtensil = tool;
} else {
writingUtensil = ‘pen’;
}
# console.log( `The ${writingUtensil} is mightier than the sword.` );
======
It returns correct result without errors, but at the button appears notification " Please do not edit writingUtensil
directly" and it doesn’t allow me to continue…
Link to the exercise:
https://www.codecademy.com/courses/introduction-to-javascript/lessons/control-flow/exercises/truthy-falsy-operators?action=resume_content_item
Thanks for any help
Hello, @ajax4973958360.
I’m not sure if you are on step 1 or step 2 of the exercise, but for step 1, we need to leave tool
assigned an empty string ''
. We also need to use the short circuit evaluation rather than if ... else
to make the assignment to writingUtensil
.
Consider this example using short circuit evaluation:
let malady = ''; //an empty string is falsy
let attribute = malady || 'bad breath'; //since malady has been assigned a falsy value, the string 'bad breath' is assigned to attribute
console.log(`My dog has ${attribute}.`);
Output:
My dog has bad breath.
If we assign malady
a truthy value:
let malady = 'fleas'; //a non-empty string is truthy
let attribute = malady || 'bad breath'; //since malady has been assigned a truthy value, its value, 'fleas' is assigned to attribute
console.log(`My dog has ${attribute}.`);
Output:
My dog has fleas.