IFSC 3300     HW3           Due by Wednesday Sept. 14, 2022

Directions: Answer the questions below, then hand in by emailing to IFSC3300HW@gmail.com. You may use JavaScript, reasoning, or both. In some of them, the best way is to try to reason them out, then try them in JavaScript to check your reasoning. You can use a sandbox to test JavaScript statements. Suggestion: hand in a link to a sandbox (or better, two links, one for questions 1-7 and one for question 8). Remember a sandbox does not have to contain code, it can contain HTML text. Or hand it in the body of an email.

(1) Give four examples of OR from daily life illustrating the four cases of true or false, false or true, true or true, and false or false. (Do not give an example of an if-then statement from daily life, and its contrapositive. Do not explain why you agree or disagree that the two if-then statements say the same thing.)

(2) Using JavaScript, write code that will print 5 lines: one for each row of the truth table for OR, plus a line containing the column labels.

Hint: \n versus <br>.You need to print out your truth table somehow. So, \n denotes the newline character (i.e. a line break) in JavaScript. On the other hand, <br> denotes a line break in HTML. Thus, if you put a \n in a string and write the string to the innerHTML of an HTML element like <p>, it will display in HTML as white space (in other words, it will print as a space or a line wrap. Instead, put the substring "<br>" in the string and HTML will render the "<br>" as the desired line break. On the other hand if you print using pure JavaScript, for example using prompt(), which creates a JavaScript popup that has nothing to do with HTML, then \n in a string will line break the string at that point. However, JavaScript does not know what <br> means because JavaScript is not HTML, so if you print that to a prompt() popup, it will print out simply as the 4 characters "<br>". Confused yet?? It will become clearer when you try it, just like so many things in programming.

(3) Using JavaScript, write code that will print 5 lines: one for each row of the truth table for AND, plus a line containing the column labels.

(4) What is the integer value of an 8-bit byte containing the following bit sequences? 

a.      00000001

b.      00000010

c.      00000011

d.      00000100

e.      00001000

f.       00001111

(5)
a. What is 7^7 in JavaScript? Explain. See https://www.w3schools.com/js/js_bitwise.asp for more information.

b. What is 7 & 7? Explain.

c. What is 7 | 7? Explain.

(6)       Pick option a, b or c.

Hint: The following example JavaScript statement might be helpful.

if (prompt('Is JavaScript fun?')==='yes') alert('You win'); else alert('you lose');