Week 10
A JavaScript function is a chunk of code designed to perform a particular task, such as calculation. Every function has a name, a list of parameters to the function, enclosed in parentheses and separated by commas, and statements that define the function, inside curly brackets.
Here is a example of a simple function
console.log(‘Hello World’);
If you want to have an alert box, you can type:
alert(“Hello World”);
if you want to have the words, write:
document.write(‘Hello World”);
Week 11
Why do we use if/else statements?
It is used to perform different actions based on different conditions.
The if/else statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed.
It works like:
if name = “Joe”;
{
alert(“hey Joe”);
}
else if (name = “Bob”);
{
alert(“Hey Bob”)
}
Leave a Reply
You must be logged in to post a comment.