Assignment 2: types and stuff
How to do this
- Go into your homework directory and run the command:
git clone https://github.com/aethertap/typescript-template hw2
- Enter the
hw2
directory and typenpm i
- Type
npm run br
- If it prints a bunch of stuff then ends up with "It works." you're good to go.
- If there are problems, let me know.
- The starting point for your program will be in
src/app.ts
, but you can add other files and import them as needed. For now,app.ts
is probably all you'll need.
Questions
- What would the equivalent code, using a while loop, be for the example
for(let i = 0; i < 10; i = i + 1) {
console.log("i is ", i);
}
-
What is the numeric value of the expression 3 < 4 ?
-
Under what conditions will this code print "water"?
if(T < 32) {
console.log("ice");
} else if(T < 212) {
console.log("water");
} else {
console.log("steam");
}
- What would this code print?
int x = 3;
if(x) {
console.log("yes");
} else {
console.log("no");
}
- (trick question) What would this code print?
int i;
for(i = 0; i < 3; i = i + 1) {
console.log("a");
console.log("b");
}
console.log("c");
- Write a function
is_binary(n:number):boolean
that checks to see whether every digit of the argument is either1
or0
.