Commit 1b0deb84 authored by Xiyang Lu's avatar Xiyang Lu

first commit add js practice

parent 767b49a8
<html>
<head>
<title>My First Program</title>
<script language = "javascript" type = "text/javascript">
let global = "this is global"
function myFunction() {
let local = "this is local"
return local
}
</script>
</head>
<body>
<script>
document.write(global)
document.write(myFunction())
</script>
</body>
</html>
\ No newline at end of file
<html>
<body>
<h1>JavaScript: Demonstrating function with parameters</h1>
<script>
// Create a function which accepts two parameters
const func = (function (personName, session) {
return "Hello " + personName + "! Welcome to " + session;
})('Pradeep','JavaScript')
// Invoke the function with parameters
// var func = myFunction()
document.write(func)
</script>
</body>
</html>
\ No newline at end of file
// Variables - Scopes
let global = "this is global"
function myFunction() {
let local = "this is local"
return local
}
console.log(global)
console.log(myFunction())
//Functions
console.log((function () {
var x = "Hello!!"
return x
})())
// Operators
let x = 10
let a = ++x;
console.log(a);
x = 10
a = x++;
console.log(a)
// Conditional statements
let text
switch (new Date().getDay()) {
case 6:
text = "Today is Saturday";
break;
case 0:
text = "Today is Sunday";
break;
default:
text = "Looking forward to the Weekend";
}
console.log(text)
//Loops
var i = 0;
for (; i < 10; ) {
console.log(i)
i++;
}
var person = {fname:"John", lname:"Doe", age:25};
var str = "";
var x;
for (x in person) {
str += person[x] + " ";
}
console.log(str)
let cars = ["BMW", "Volvo", "Mini"];
let text = "";
for (let x of cars) {
text += x + " ";
}
console.log(text)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment