Why does one IF statement not need curly brackets and the other one does?


#1


https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/1?curriculum_id=506324b3a7dffd00020bf661#


My code is correct but I am wondering why the first if statement doesn't need to be wrapped in curly brackets

1)
if (computerChoice < 0.34) {
computerChoice = "rock";
}

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

Why is this? Does anybody know? Thanks for your help folks.

/*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!";
}
};


#2

Everything here:

is basically setting the conditions for which

will be printed. Hence they each stand alone.

For

the first curly bracket is for the function and the second is for the conditional statement.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.