diff --git a/pset1.js b/pset1.js index 6ac27bd..2d6e961 100644 --- a/pset1.js +++ b/pset1.js @@ -15,6 +15,16 @@ What are the types of the following expressions and what do they evaluate to, an ******************/ +/* 17 is a number and evalutates to 17. + 1 + 2 * 3 + 4 is a number and evaluates to 11 because of PEMDAS rules. + 800/ 80 / 8 is a number and evaluates to 1.25 because of PEMDAS rules. + 400 > 200 is a boolean and evaluates to true because the statement is true. + 1 !== 1 is a boolean and it evaluates to false because the statement is false. + true || false is a boolean and it evaluates to true because a statement can be true or false. + true && false is a boolean and it evaluates to false because a statement can not be true and false. + 20 % 6 is a number and it evaluates to 2 because that is the remainder of 20/6. + 'a' + 'b' is a string and it evaluates to ab because they are combined by the + operator. + */ /****************** @@ -29,7 +39,12 @@ What will the following return? Why? ******************/ - +/* typeof 4 will return number because 4 is a number. + type of 'hello' will return string because anything in quotes is read as a string. + typeof true will return boolean because anything with a true or false value is a boolean. + 2 === 1 || 3 === 4 will return false because this statement is a boolean because of the === and || operators and + when both values are evaluated and compared, both sides are false therefore the entire statement is false. +*/ /****************** PROBLEM 3: @@ -46,7 +61,13 @@ For reference, here is a truth table for the expression A && B: ******************/ +/* | A | B | A || B| + | true | true | true | + | false | true | true | + | true | false | true | + | false | false | false | +*/ /****************** PROBLEM 4: @@ -63,6 +84,12 @@ For reference, here is a truth table for the expression A && !B: ******************/ +/* | A | B | !A | !B | !A &&!B | + | true | true | false | false | true | + | false | true | true | false | false | + | true | false | false | true | false | + | false | false | true | true | true | + /****************** @@ -79,7 +106,11 @@ For reference, here is a exp of a step-by-step evaluation: ******************/ - +/* 2 + 3 * 2 + 1 + 2 + 6 + 1 + 8 + 1 + 9 +*/ /****************** PROBLEM 6: @@ -89,7 +120,11 @@ Write a step-by-step evaluation for the following expression (remember order of ******************/ - +/* 4 / 2 + 8 / 4 + 2 + 8 / 4 + 2 + 2 + 4 +*/ /****************** PROBLEM 7: @@ -100,11 +135,23 @@ Write a step-by-step evaluation for the following expression: 'ca' + 'ter' + 'pi ******************/ +/* 'ca' + 'ter' + 'pi' + 'llar' + 'cater' + 'pi' + 'llar' + 'caterpi' + 'llar' + 'caterpillar' +*/ /****************** PROBLEM 8: Write a step-by-step evaluation for the following expression: 2 * 4 === 8 && 'car' + 'pool' === 'carpool'. +******************/ -******************/ \ No newline at end of file +/* 2 * 4 === 8 && 'car' + 'pool' === 'carpool' + 8 === 8 && 'car' + 'pool' === 'carpool' + true && 'car' + 'pool' === 'carpool' + true && 'carpool' === 'carpool' + true && true + true +*/ \ No newline at end of file