FAQ: Control Flow - Putting It All Together

Hello,
Thank you for the note about Modern JS inserting semicolons automatically. I also did with and without - both worked. as long as we have { and } to start and finish, right?

Pretty much, yes. Blocks need to be defined with braces, and statements that occupy their own line don’t need semi-colons. To be on the safe side, though, using them is not such a bad thing.

2 Likes

I have read this entire thread and have tried all the suggestions and it still is not working. When i click on ‘Give me the solution’, nothing happens. Can someone post the solution?

I’m not sure what I did different, I had this:
if (mode === ‘public’) {
showDetails();
} else {
hideDetails();
}

Did you take out the extra text?

HI, I am new to coding…
Question…how does the computer know what to show in this example… Is there another coding behind, what the problem is here to solve?

Good day guys, I tried to run this code but its not working. pls can someone help me out?
if (mode === ‘showDetails’) {
// Call a function here to show the post details

} (else === ‘hideDetails’) {
// Call a function here to hide the post details

}

Hello, everyone, I was wondering if anyone could answer why do we have to use brackets after showDetails, why is that?

capitalization of the D worked. TY

it worked. thanks. with or without the ;

Hi People!

I was wondering why do we need to capitalize the D in showDetails or hideDetails ??
In the other lessons i think i read that the code ist mostly lowercase, but why in this instance must be capitalized??
Nice week yall!

Because of camelCase

camelCase: showDetails()

normal/original word: show details

For single word, one can go with lower case(here the square)

function square{
    //statements
}

In Javascript, We follow this for naming variables, methods, and functions etc. Javascript follows camelCase style naming convention for multiple words.

camelCase Rules:

  1. Remove the spaces between multiple words and make them all into a single word.
  2. The first word in lower case/small letters.
  3. Capitalize the only first letter of each following word

Original word/Raw word: Putting It All Together

camelCase: puttingItAllTogether

Other style types:

  • PascalCase (first letter capital in every word)
  • snake_case (underscore between words)
  • SNAKE_CASE (ALL CAPS)
  • kebab-case (dash between words)

https://www.codecademy.com/paths/code-foundations/tracks/learn-how-to-code/modules/bop-ii/lessons/bop-control-flow/exercises/control-all-together

2 Likes

Thank you for the response, interesting!

Thanks man! That did it for me.

if (mode === ‘public’) {
// Call a function here to show the post details
showDetails();

} else {
// Call a function here to hide the post details
hideDetails();

}

*Note Make sure you watch your spelling and CASE sensitivity. Mine works with and without semicolons.

I know this is a very old post but just incase anyone is currently stuck, It wasn’t working for me for a while even with the cheat sheet but after I restarted I just got rid of the // slashes and the words after and then it worked.

Welcome to the forums!

There must have been something wrong with the learning environment itself. // denotes a comment in JavaScript (as well as several other languages). Comments are ignored by the interpreter, meaning they are not executed. Everything starting from // to the end of the line will be ignored.

Comments are often used to document your code or clarify it. Although the following example doesn’t need a comment to indicate what is being printed (since it is fairly obvious and the code is very simple), it demonstrates how a comment could be used. // prints 5 is ignored by the interpreter and will not execute.

let x = 5;
console.log(x); // prints 5