Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions pset1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/


/******************
Expand All @@ -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:

Expand All @@ -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:
Expand All @@ -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 |



/******************
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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'.

******************/

******************/
/* 2 * 4 === 8 && 'car' + 'pool' === 'carpool'
8 === 8 && 'car' + 'pool' === 'carpool'
true && 'car' + 'pool' === 'carpool'
true && 'carpool' === 'carpool'
true && true
true
*/