Java is NOT JavaScript
for my working page go here
what makes our page dynamic: html is sctucture css details (sofa) js what makes it all work
JS can store data and change based on user input. It is HUGE and can do a lot!
What is a variable? In programming, a variable is a value that can change, depending on conditions or on information passed to the program. Typically, a program consists of instruction s that tell the computer what to do and data that the program uses when it is running. js_variables
The var keyword was used in all JavaScript code from 1995 > to 2015.
The let and const keywords were added to JavaScript in 2015.
The var keyword should only be used in code written for older browsers.
- console.log(“this is a test”);
- let myName = “Jessica”;
- console.log(myName);
// data types
- let myPet = “Dog”; // this data is a string
- let myPetsAge = 7; // this data is a number
- let petDetails = “My pet is “ + myPetsAge; // this will print as a string
- console.log(petDetails);
- console.log(typeof petDetails); // will tell us what type the data is
- let likesWalkies = true // this data type is a boolean true/false statement
- console.log(typeof likesWalkies);
// other types are arrays and objects
// arethemetic operators
- let addition = 7 + 7 // + is for addition
- console.log(addition)
- let subtraction = 5 - 2 // - is for subtraction
- console.log(subtraction)
- let multiplication = 2 * 3 // * is for multiplication
- console.log(multiplication)
- let division = 15 / 3 // / this is for division
- console.log(division)
- let myNum = 5
- let thisNum = ++myNum //++ is to increment (will look different if ++ is put at the end)
- console.log(thisNum)
- let thatNum = –myNum // – this will decrement by one
- console.log(thatNum)
// Comparison operators
- // == equal to
- // === equal value and equal type “7” === 7
- // != not equal
- // !== not equal value and not equal type
- // > greater than
- // < less than
- // >= greater than or equal to
- // <= less than or equal to
// Methods
// consol.log()
// prompt()
// document.write() !!! DO NOT USE THIS AS IT WILL OVERWRITE HTML
// alert() will show a message to the user
let userName = prompt(“Hi user :) please tell me your prefered name!”)
console.log(userName)
// if (userName == “Je”){ // } else (alert(“Please enter your name”))
const welcomeMsg = alert(“Welcome to my page “ + userName)
document.write()
In programming, a variable is a value that can change, depending on conditions or on information passed to the program.
Declaration of a variable in a computer programming language is a statement used to specify the variable name and its data type. Declaration tells the compiler about the existence of an entity in the program and its location. When you declare a variable, you should also initialize it.
The assignment operator = assigns the value of its right-hand operand to a variable, a property, or an indexer element given by its left-hand operand. The result of an assignment expression is the value assigned to the left-hand operand.
we use the prompt() function to ask the user for input. As a parameter, we input the text we want to display to the user. Once the user presses “ok,” the input value is returned. We typically store user input in a variable so that we can use the information in our program.