Skip to content

Commit 6a0ea8b

Browse files
authored
Update javascript_for_web.js
Functions and NextInLine
1 parent 050d951 commit 6a0ea8b

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

javascript_for_web.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,102 @@ function checkBalance(amount){
531531
bankBalance = console.log(checkBalance(200)); //500
532532

533533
// UPNEXT: STAND IN LINE;
534+
//This works similar to Queues and stacks in computer sciece;
535+
//Boolean Values: True/fals , on/off 1/0
536+
//Conditional statements with if logic (used to make decisions)
537+
//comparison with equality operator (uses equal sign to do comaprison between operators);
538+
//comaparison with the strict equality operator; (===) has no type of conversion unlke == where we can compare ints n strings by converting them to strings
539+
//practise comparing different values === & == in one function . conversioncacn happens using .typeOf Function.
540+
function nextInLine(arr, item) {
541+
arr.push(item);
542+
return arr.shift();
543+
}
544+
var testArr = [1,2,3,4,5];
545+
console.log("Before: " + JSON.stringify(testArr));
546+
console.log(nextInLine(testArr, 8));
547+
console.log("After: " + JSON.stringify(testArr));
548+
549+
550+
//boolean
551+
function welcomeToBooleans() {
552+
return true;
553+
}
554+
console.log(welcomeToBooleans()); // Reurns true
555+
556+
//if statements
557+
//Ex1
558+
function test (myCondition) {
559+
if (myCondition) {
560+
return "It was true";
561+
}
562+
return "It was false";
563+
}
564+
test(true); // returns "It was true"
565+
test(false); // returns "It was false"
566+
567+
// Ex2
568+
function ourTrueOrFalse(isItTrue) {
569+
if (isItTrue) {
570+
return "Yes, it's true";
571+
}
572+
return "No, it's false";
573+
}
574+
console.log(ourTrueOrFalse(true));
575+
576+
//ex3
577+
function trueOrFalse(wasThatTrue) {
578+
if(wasThatTrue){
579+
return "Yes, that was true";
580+
}
581+
return "No, that was false";
582+
}
583+
584+
console.log(trueOrFalse(false));
585+
586+
//comparison
587+
//Ex1
588+
function equalityTest(myVal) {
589+
if (myVal == 10) {
590+
return "Equal";
591+
}
592+
return "Not Equal";
593+
}
594+
// Ex2
595+
function testEqual(val) {
596+
if (val==12) { // Change this line
597+
return "Equal";
598+
}
599+
return "Not Equal";
600+
}
601+
console.log(testEqual(10));
602+
//Ex3
603+
function comapreTwoVal(nums){
604+
if(nums == 50){
605+
return "Equal to 50";
606+
}
607+
return "Not equal to 500";
608+
}
609+
console.log(comapreTwoVal(50));
610+
611+
612+
//Strict comparison:
613+
614+
function testStrict(val) {
615+
if (val === 7) {
616+
return "Equal";
617+
}
618+
return "Not Equal";
619+
}
620+
console.log(testStrict(7)); //Equal
621+
622+
623+
function strictTestNotSameType(num){
624+
if(num===10){
625+
return "strictly equal";
626+
}
627+
return "Not strictly Eqaul";
628+
}
629+
console.log(strictTestNotSameType("10")); // Not eqal
630+
534631

632+
//practise comapring comparisons

0 commit comments

Comments
 (0)