initial javascript port of asst1.