I'm learning Javascript and I'm totally confused. The curly braces "{" and "}" use is annoying the crap out of me. I don't really understand their placement.
For example I have a script that will ask three questions and based upon the answer provided by the user will return a suitable response. Now the use of the curly braces has me totally confused so much so that I cannot decipher the correct method to write such a script.
For the purpose of this question following is an example script for the scenario I mention above:-
So there's curly braces all over the place and I just don't understand which set of two each are meant to be around what part of the code and why. Which of course makes the whole damned thing confusing when designing a script.
Can anyone offer some advice please?
For example I have a script that will ask three questions and based upon the answer provided by the user will return a suitable response. Now the use of the curly braces has me totally confused so much so that I cannot decipher the correct method to write such a script.
For the purpose of this question following is an example script for the scenario I mention above:-
<script>
if (confirm("Is the weather clear?")) {
if (confirm(Is it before 5pm?")) {
if (confirm(Is the primary route congested?")) {
alert("Take alternative \"B\" Home")
}
else {
alert("Take primary route home")
}
}
else {
alert("Take alternative \"A\" Home")
}
}
else {
alert("Take alternative \"A\" Home")
}
alert ("Arrive home safely")
</script>
So there's curly braces all over the place and I just don't understand which set of two each are meant to be around what part of the code and why. Which of course makes the whole damned thing confusing when designing a script.
Can anyone offer some advice please?