Syntax questions- {} curly brackets surrounding if


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

``` Hello elders of JS,

I went forward but came back because I dont understand a syntax issue.
When do you use curly brackets,{}?
Here after if (computerChoice < 0.34) you put a {, but then down the page
you place one before the if (choice1 === choice2)statement.

I am confused about the use cases for {} and
why they are used in different places?

/var userChoice = prompt(“Do you choose rock, paper or scissors?”);
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = “rock”;
} else if(computerChoice <= 0.67) {
computerChoice = “paper”;
} else {
computerChoice = “scissors”;
} console.log("Computer: " + computerChoice);
/

var compare = function(choice1, choice2)

{
if (choice1 === choice2) {
return “The result is a tie!”;
}

else if (choice1 ===“rock”) {
if (choice2 ===“scissors”)
return “rock wins”;
else
return “paper wins”;
}
}

<do not remove the three backticks above>

#2

Curly braces are commonly used for conditionals, functions, and objects.

You must use one to start, and end the latter.

Examples:

//Function
function talk() { //Start
console.log("Hello!");
}; //End

//Object
var name = { //Start
first: "John",
last: "Doe"
}; //End

//Conditionals
if (1 > 2) { //Start if
console.log("what?");
} //End if
else if (1 == 2) { //Start else if
console.log("Math?");
} //End else if
else { //Start else
console.log("The world makes sense");
} //End else

#3

Thank you for replying, I think the issue was that the second one was nested within a function? Is this the right diagnosis?