Welcome to BHS Computer Science. If you are a student in the class, the first thing you need to do (and which we should have done in class) is set up your GitHub account.
Once you have a GitHub account, click “Log in to GitHub” below to proceed. Or you can click “Use anonymously” to play with the environment but you will not be able to save your work or submit assignments. (You can always log in later by clicking the at the top of the page.)
If you don’t have a GitHub account yet, please create one and then log in here for further instructions.
Congratulations! You have successfully connected this app to GitHub. However you are not yet a member of the GitHub organization for this class, something Mr. Seibel needs to set up for you.
This is your GitHub profile URL:
Click the clipboard icon to copy it and then submit it at this form so he can add you.
Congratulations! You have successfully connected this app to GitHub. And it looks like you have an invitation to join the GitHub organization for this class. You need to accept that invitation before you can proceed. The invite should be sent to whatever email you used when you created your GitHub account.
I see you are logged into GitHub and a member of the berkeley-high-cs GitHub organization. However there seems to have been some problem finishing the setup for your account. Please let Mr. Seibel know.
This is a tool for the BHS Computer Science class at Berkeley High School. It is intended to provide a simple environment for experimenting with Javascript without all the complexities of a full development environment such as ReplIt or Glitch which we may use later in the year.
It is also designed to take advantage of the browser’s ability to run Javascript natively. It does not need access to a server to run code making in extremely responsive even if the Wifi is flaking out.
Finally, under the covers it is saving work to a GitHub repository in a very simplified workflow that does not depend on immediately learning any git commands. Code written in this environment for each assignment is saved to a directory and branch specific to that assignment each time it is saved. Thus when the assignment is done, it is easy to go to GitHub and create a PR containing just the work on that assignment which can then be commented on and worked on further before it is turned in and merged to main.
You're all set! You don't need to worry about this yet but we have successfully created a GitHub repository for your work:
You can get to it any time by clicking on your GitHub username at the top-right of the screen.
For a change of pace, this assessment does not require you to write code. Instead you will need to read some code and answer questions about it. It is a closed book assessment and you should keep your eyes on your own screen and not talk with your neighbors while you take it. You do not need to submit a pull request this time; your answers are saved automatically when you select from a multiple choice answer or hit enter on a free-form answer.
When this code runs, does it call the foo
function?
let x = 10;
if (x % 2 === 0) {
foo();
}
Yes
No
When this code runs, which functions are called?
let x = 37;
if (x < 37) {
foo(x);
} else {
bar(x);
}
Just foo
Just bar
Both foo
and bar
Neither foo
nor bar
.
When this code runs, which functions are called?
let x = 37;
if (x * -1 < 37) {
foo(x);
}
bar(x);
Just foo
Just bar
Both foo
and bar
Neither foo
nor bar
.
In this code:
let x = 0;
for (let i = 0; i < 10; i++) {
x = x + i * 10;
}
what part is the “condition” of the for
loop.
let x = 0
let i = 0
i < 10
i++
x = x + i * 10
Given this definition:
const N = 100;
How many times does the body of this loop execute?
for (let i = 0; i < N; i++) {
// code here
}
99
100
101
To fully understand this code you should know that
Math.random()
is a function that returns a random
number between 0 and 1. With that in mind, after this code runs:
let randomNumbers = [];
for (let i = 0; i < 10; i++) {
randomNumbers.push(Math.random());
}
What does the following expression evaluate to?
randomNumbers.length
We can’t know, it’s random.
It’s random but definitely at least 10.
It’s random but definitely less than 10.
It’s random but definitely a multiple of 10.
10
Less than 10
How many times is the foo
function called when this
code runs:
for (let i = 0; i < 5; i++) {
for (let j = 0; j < 4; j++) {
foo(i, j);
}
}
4
30
5
20
12
Given this code:
let c = 0;
for (let i = 0; i < 4; i++) {
for (let j = 0; j < i; j++) {
c++;
}
}
what is the value of c
after the loop finishes?
4
3
6
10
Given this code:
let x = 0;
for (let i = 0; i < 10; i++) {
x = x + i;
}
What is the best description of the value of x
after
the loop has completed?
The sum of the numbers from 0 to 10
The sum of the numbers from 0 to 9
The number of elements in the array x
11
What is the best description of when this loop will stop?
let done = false;
while (!done) {
const r = Math.random();
done = r < 0.01;
}
Never, it’s an infinite loop
Immediately, the loop body never executes
When Math.random()
returns a number less that 0.01
When Math.random()
returns a number greater than
0.01
When done
is less than 0.01
In the following code, assume isPrime
is a function
that says whether the number it is passed is a prime number.
const foo = (limit, max) => {
let primes = 0;
for (let n = 0; n < max; n++) {
if (isPrime(n)) {
primes++;
}
if (primes > limit) {
return true;
}
}
return false;
}
Which of the following best describes what this function does?
It tests whether limit
is a prime number.
It tests whether there are at most max
prime
numbers below limit
.
It tests whether there are more than limit
prime
numbers below max
.
It tests whether limit
and max
are
both prime numbers.