Art of Code — Problem Set 0
The simplest definition of programming is giving a computer instructions in order to carry out a task. A programs size and complexity will grow out of control, confusing even the person who created it. Keeping programs under control is the main problem of programming.
Javascript programs consist of variables , datatypes , and operators in which I will define below:
Variables are containers for storing data values.
var x = 5;
var y = 6;
var z = x + y;
Variables can hold many datatypes: numbers, strings, arrays, objects and more. In programming, data types is an important concept. To be able to operate on variables, it is important to know something about the type. Without data types, a computer cannot safely solve equations.
Examples:
var length = 43; // Number
var lastName = “Moss”; // String
var cars = [“GMC”, “Audi”, “BMW”]; // Array
var x = {firstName:”Shakir”, lastName:”Moss”}; // Object
To determine the logic between variables and values , logical operators are used. Logical operators are typically used with Boolean (logical) values. When they are, they return a Boolean value. However, the && and || operators actually return the value of one of the specified operands, so if these operators are used with non-Boolean values, they may return a non-Boolean value
Now is a perfect time to explain if and else statements. The “if” statement is used to specify a block of JavaScript code to be executed if a condition is true.
Example:
Make a “Good Evening” greeting if the hour is less than 21:00:
if (hour < 21) {
greeting = “Good Evening”;
}
Else statement is used to specify a block of JavaScript code to be executed is false.
if (hour < 21) {
greeting = “Good Evening”;
} else {
greeting = “Good Morning”;
}
This concludes the writing exercise.