Commit 2d8dabb5 authored by Julius Wu's avatar Julius Wu

complete assignment

parents
//Basic JavaScript Examples
// Variables - Scopes
var global = "-global"
function variablesScopesExample() {
var local = "-local"
console.log("this is local in the function " + local);
console.log("this is global in the function " + global);
}
console.log("this is global in the main " + global);
variablesScopesExample();
//this is global in the main -global
//this is local in the function -local
//this is global in the function -global
// Functions
function noParm(){
return("hello world")
}
noParm(); //hello world
function withParms(n1, n2){
return n1+n2;
}
withParms(1,2); //3
function withParms2(name, companyname){
return("My name is "+ name+ " " +"I work for " + companyname);
}
withParms2("Julius", "Nisum"); //My name is julius I work for Nisum
withParms2("Julius"); //My name is julius I work for undefined
withParms2(); //My name is undefined I work for undefined
// Operators
let a = 10;
console.log(a)
let pre = ++a;
console.log(a); //11
console.log(pre); //11
let after = a++;
console.log(a); //12
console.log(after); // 11
let c = 2;
let d = 'hello';
console.log(c += 3); //5
console.log(d += ' world'); // hello world
console.log(true || false); // true
console.log(false || true); // true
console.log(true || true); // true
console.log(false || false); // false
console.log(false && false); // false
console.log(true && false); // false
console.log(false && true); // false
console.log(true && true); // true
// Conditional statements
function evenOrOdd(num){
if(num%2===0){
console.log("even");
}else{
console.log("odd");
}
}
evenOrOdd(1) //odd
evenOrOdd(2) //even
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}; //Friday (as of April 9, 2021)
// Loops
let arr = ["a","b","c"];
for(ele in arr) { console.log(ele)} // 0,1,2
for(ele in arr) { console.log(ele)} // a,b,c
for(let i=0; i<arr.length; i++){
console.log(i);
console.log(arr[i]);
} // 0 , a , 1 , b , 2 , c
let i=0;
while(i<arr.length){
console.log(i);
console.log(arr[i]);
i++;
} // 0 , a , 1 , b , 2 , c
let result = ''
let i=0;
do {
i = i + 1;
result = result + i;
} while (i < 5); // "12345"
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