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.
This assessment consists of functions you need to write involving manipulating arrays and objects. And maybe arrays of objects. It is a closed book assessment. You should stay on this tab until you are done and there should be no talking. This assessment is about how much you understand. There are no automatic tests but you can use the REPL to test things yourself.
Note: on this assessment you will be asked to write functions that call other functions you will write as part of the assessment. If you don’t know how to write one function you can still get full credit for a function that is supposed to call it as long as your code calls it appropriately, i.e. with correct syntax and passing the right arguments.
You can move through the questions with the arrows at the upper right
next to the 1 of indicator so if
you're not sure how to write one function move on to another one and
come back if you have time at the end. I want to see how much you do
know. Note: you can also click on
thingsLikeThis
in these instructions and the questions to
copy them to the clipboard to avoid spelling mistakes. (I.e. click to
copy and then ⌘-v to paste wherever you want.)
When you are done, please click on your Github username above
and submit a GitHub pull request of the branch
and request me as a reviewer. Doing
this correctly is part of the assessment.
If you are unsure how to request a review, please ask for help!
Write a function named makeRow
that takes no
arguments and returns a new three-element array where each
element is the empty string, ''
.
Write a function named makeBoard
that takes no
arguments and returns a 3x3 array. That is, it should return an
array containing three elements, each of which is a new array
containing three elements. The elements of the inner arrays
should all be the empty string, ''
. In other words,
the inner arrays are rows such as are returned by the
makeRow
function you just wrote, which you are free to use here if you
want.
Write a function named makeMove
that takes three
arguments: a string, specifying a mark (either
'X'
or 'O'
); a number specifying a
row; and a number specifying a column. It should return an
object with three properties, mark
,
row
, and column
, each with the value
of the corresponding argument.
Write a function named placeMark
that takes a 3x3
array like the ones returned by makeBoard
and an
object like the ones returned by makeMove
and sets
the element of the array at the row and column specified in the
move object to the move's mark.
The function does not need to return any specific value but after calling it the array passed as the first argument should be modified. For instance, after:
let board = makeBoard();
let move = makeMove('X', 1, 1);
placeMark(board, move);
the expression board[1][1]
should evaluate to
'X'
.
Write a function named allTheSame
that takes an
array of three elements and returns true
if all
three elements are ===
to each other and
false
otherwise. For instance,
allTheSame(['X', 'X', 'X'])
should return
true
.
Write a function named extractColumn
that takes a
3x3 array like the ones returned by makeBoard
and
an index from 0 to 2, inclusive, and returns a three-element
array containing the values in the column specified by the
index, assuming the inner arrays represent rows. For instance if
board
is the array:
[
['X', '', ''],
['O', '', ''],
['', 'X', '']
]
then extractColumn(board, 0)
should return
['X', 'O', '']
Write a function named recordMove
that takes two
arguments: an array and a move object, like the ones returned by
makeMove
. It should add the given move to the end
of the array.
The function does not need to return any specific value but after it is called the array argument should be one longer than it was before the call and the last element of the array should be the object passed as the second argument.
Write a function named rowForMove
that takes two
arguments: an array of move objects like the ones collected in
recordMove
and a number which is an index into that
array. It should return the row value (a number) of the move at
the given index.
For example after these two lines are executed:
let moves = [];
recordMove(moves, makeMove('X', 1, 2));
the call rowForMove(moves, 0)
should return
1
.
Write a function named placeMoves
that takes two
arguments: a 3x3 array like the ones returned by
makeBoard
and an array of moves such as might be
built up by repeatedly calling recordMove
. The
function should call placeMark
to place the mark
for each move in the array of moves in the correct position on
the board array.
The function does not need to return any specific value though
obviously all the calls to placeMark
will have
updated the board array argument. For instance after these lines
are executed:
let moves = [];
let board = makeBoard();
recordMove(moves, makeMove('X', 1, 1));
recordMove(moves, makeMove('O', 0, 0));
recordMove(moves, makeMove('X', 0, 1));
placeMoves(board, moves);
then the board
should be in this state:
[['O', 'X', ''], ['', 'X', ''], ['', '', '']]