JavaScript

JavaScript

Shokhrukh
  1. alert ("Hello My Name Is Shokhrukh

alert (123) // This is a string

alert(2+2) // displays 4


var name;

  1. name = "Shokhrukh"; // Shoulh be declared once
  2. var number = 11 // Number
  3. var number = "11" // A String (word)
  4. var camelCaseMethodOfUsingVariableNames
  5. % gives you remainder e.g. var remainder = 19 % 3 // = 2
  6. num++ // num = num +1; increments by 1
  7. num-- // num = num - 1; decrement by 1

var num = 1;

var newNum = num-- // newNum=1; num = 0;

var num = 1;

  1. var newNum = --num // newNum=0; num= 0;
  2. totalCost = 3 + 3 * 4 //15; But use barantheses. It is better for you e.g. 3+(3*4)

Concatenating:

  1. alert("Thanks, " + userName + "!");

Prompts are like Alerts:

  1. var person = prompt("What is your name?", "Your Name"); // Arguments are always strings
  2. if (x === correctAnswer) {} // tripple equal sign
  3. !== // does not equal to smth

if (x === "Vatican") {

alert("Correct!");

}

else if (x==="Rome") {

alert("Incorrect but close"

}

else{

alert("Incorrect")

  1. }






Report Page