JavaScript
Shokhrukh- alert ("Hello My Name Is Shokhrukh
alert (123) // This is a string
alert(2+2) // displays 4
var name;
- name = "Shokhrukh"; // Shoulh be declared once
- var number = 11 // Number
- var number = "11" // A String (word)
- var camelCaseMethodOfUsingVariableNames
- % gives you remainder e.g. var remainder = 19 % 3 // = 2
- num++ // num = num +1; increments by 1
- num-- // num = num - 1; decrement by 1
var num = 1;
var newNum = num-- // newNum=1; num = 0;
var num = 1;
- var newNum = --num // newNum=0; num= 0;
- totalCost = 3 + 3 * 4 //15; But use barantheses. It is better for you e.g. 3+(3*4)
Concatenating:
- alert("Thanks, " + userName + "!");
Prompts are like Alerts:
- var person = prompt("What is your name?", "Your Name"); // Arguments are always strings
- if (x === correctAnswer) {} // tripple equal sign
- !== // does not equal to smth
if (x === "Vatican") {
alert("Correct!");
}
else if (x==="Rome") {
alert("Incorrect but close"
}
else{
alert("Incorrect")
- }