#Help Required for Coding Rooms Javascript Beginner Task

23 messages · Page 1 of 1 (latest)

deep folio
#

Given a string value word, use a conditional statement to set the lastWord variable to:

the upper-cased string stored in word if the word starts with the letter m and has a length of 10.

the unmodified string stored in word if it is any other length or does not start with a m.

My example below:

let word = 'med';
// let word = 'bedazzling';
// let word = 'piza';
// let word = 'pizzicatos';
// let word = 'mizzenmast';
// let word = 'motivation';

let lastWord;

// YOUR CODE
if(word[0]--'m' && word.length --10){
console.log(lastWord = word.toUpperCase());
}
else {
lastWord = word;
}

// DO NOT EDIT BELOW

module.exports = {word, lastWord};

deep folio
#

I had "=" but I saw an example with "- -" instead on W3Schools so I've replaced them with that

red sparrow
#

So you don't understand what you're doing?

#

Fundamentally, that is the problem

#

You are trying to do an equality chexk

#

Which is done by either using == or ===

#

Are you familiar with either of those

deep folio
red sparrow
#

So why are you using --? That's what I'm not understanding

deep folio
#

I'm not sure 😂 I'm new to JS, I had the equal signs previously but removed them as I was trying out a few different things. I started my JScourse 2 days ago so I'm entirely new to this.

red sparrow
#

One tip from me. Don't try things you don't understand

#

If you want to try things, then understand them first

#

-- is the decrement operator if I'm not mistaken

#

Which will subtract one from an integer and replace it

deep folio
#

Noted, thank you

red sparrow
#

Which is obviously not what you want

deep folio
#

it's now worked

#

let word = 'mizzenmast';
// let word = 'bedazzling';
// let word = 'piza';
// let word = 'pizzicatos';
// let word = 'mizzenmast';
// let word = 'motivation';

let lastWord;

// YOUR CODE
if(word[0] === 'm' && word.length === 10){
console.log(lastWord = word.toUpperCase());
}
else {
console.log(lastWord = word);
}

// DO NOT EDIT BELOW

module.exports = {word, lastWord};

#

thank you

red sparrow
#

No worries lol

#

But again, you probably could've figured it out yourself if you understood what the decrement operator does

#

Which would have prevented you from trying it