From 88ffefa4beed47f827c5b0adcc5abc225607a013 Mon Sep 17 00:00:00 2001 From: Tina Sharma Date: Mon, 13 Jul 2015 18:49:16 -0700 Subject: [PATCH] first add and commit of lab1 --- .DS_Store | Bin 0 -> 6148 bytes lab1.js | 41 ++++++++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..810a83413db1cfa3f198ff5ebe1ee8393df87000 GIT binary patch literal 6148 zcmeHKK~BR!3>=ptTG2y~9CPGUsXqu+3*x|~JOF452na0#de1X>6c6AxW$d-8l$0w% zU`zJwI(D4QuHq~J87yagpbMZyRcy3rwuoL=tx3Z@yF{^jyy6CTC~%ElEjk>(kpW%1 z4o>ilCFZEE-#uPVi^X(OEGCT64RTC9T$ykL>~W>9FhQTIU5|d(Xli4%(qLAZV}Tj> z#swa2w6vYFt;$=aN(WD@GQ|V!t?ew150rT2H)Q8)J-cgdxs|J=UCk$@tKW zN+nK1f`MQl82A?quxG2Z_7jE;27-ZLV9kJjA2O<9?pP+YPX~=10fu-95kpcs{h7z*j%C7>4)Mc>cxCYuidc2tKeKR1o-k}M5DaWGu#=`; z?f;|i&;OfAF$)HQfj`B7G>7NI0bj{`YwhK<*Jjj9s*1*y3D+qcSSx0%w&DY-3H_N4 Vh`D2#kRD3>2pA1vf`K1p;1dB@N)G@4 literal 0 HcmV?d00001 diff --git a/lab1.js b/lab1.js index 52fed9d..ac46abd 100644 --- a/lab1.js +++ b/lab1.js @@ -42,11 +42,10 @@ function assert(expression, failureMessage) { Below are some examples for how to use the assert method. Tip: once you've run this file a couple times to see how they work, comment them out. - That will help later when you run jscs. -*/ + That will help later when you run jscs.*/ -assert(1 === 1, '1 equals 1 - this assert will pass.'); -assert(1 === 2, 'this is an example of a failing assertion. 1 does not equal 2.'); +//assert(1 === 1, '1 equals 1 - this assert will pass.'); +//assert(1 === 2, 'this is an example of a failing assertion. 1 does not equal 2.'); /* =========================================================================== ------------------Assertions (8 points total)--------------------------------- @@ -61,6 +60,12 @@ assert(1 === 2, 'this is an example of a failing assertion. 1 does not equal 2.' //your code goes here +var fox = 'What does the fox say?'; +var foxSound = ''; + +assert(fox === 'What does the fox say?', 'Do you know what the fox say?'); +assert(foxSound === 'Moo', 'Do you really think that is what the fox says?'); + /* ======================================================================== ----------------- Meerkats (20 points total)------------------------------- =========================================================================== @@ -82,11 +87,29 @@ var sentence2 = 'Come over here so you can scratch my belly.'; // your code goes here +var sent1 = sentence1.split(' '); + +for (var i = 0; i < sent1.length; i++) { + sent1[i] = 'chirp'; +} + +sentence1 = sent1.join(' ') + '.'; + // TODO: part #2: use a while or do-while loop to replace the words in sentence 2 // with 'chirp' (10 points) // your code goes here +var sent2 = sentence2.split(' '); +var j = 0; + +do { + sent2[j] = 'chirp'; + j++; +} while (j < sent2.length); + +sentence2 = sent2.join(' ') + '.'; + // Leave these assertions as-is! If they pass, your code works. assert(sentence1 === 'chirp chirp chirp.', 'sentence 1 should have 3 chirps'); assert(sentence2 === 'chirp chirp chirp chirp chirp chirp chirp chirp chirp.', @@ -109,6 +132,8 @@ var nextAnimal; // your code goes here +nextAnimal = Math.random(favoriteAnimals); + assert(nextAnimal, 'assign something to nextAnimal'); /* ===================================================================== @@ -124,10 +149,10 @@ assert(nextAnimal, 'assign something to nextAnimal'); // don't require quotes for the code to work. Remove the unnecessary quotes. var animalExhibitStats = { - 'numberOpen': 13, + numberOpen: 13, 'number closed': 2, 'petting-zoo-open': true, - 'mostPopular': 'Lucky the Emperor Penguin', + mostPopular: 'Lucky the Emperor Penguin', '2ndMostPopular': 'Dumbo the Depressed Donkey' }; @@ -138,7 +163,7 @@ var animalExhibitStats = { notation with dot notation wherever possible. */ -assert(animalExhibitStats['numberOpen'] === 13, 'there should be 13 open exhibits'); +assert(animalExhibitStats.numberOpen === 13, 'there should be 13 open exhibits'); assert(animalExhibitStats['number closed'] === 2, 'there should be 2 closed exhibits'); assert(animalExhibitStats['petting-zoo-open'], 'hey! =( i was promised meerkats!'); assert(animalExhibitStats['2ndMostPopular'] === 'Dumbo the Depressed Donkey', @@ -150,6 +175,8 @@ assert(animalExhibitStats['2ndMostPopular'] === 'Dumbo the Depressed Donkey', // your assert goes here +assert(animalExhibitStats.mostPopular === 'Lucky the Emperor Penguin', + 'The Emperor Penguin is Lucky'); /* ================================================================== ----------------- Code Style (10 points) ---------------------------- =====================================================================