From 01c5733db75de68ef9f49893e99627e46781cf96 Mon Sep 17 00:00:00 2001 From: Purvesh Date: Fri, 21 Sep 2018 13:07:19 +1000 Subject: [PATCH] checkpoint assessment --- week1_ass.purve.js | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 week1_ass.purve.js diff --git a/week1_ass.purve.js b/week1_ass.purve.js new file mode 100644 index 0000000..308a6db --- /dev/null +++ b/week1_ass.purve.js @@ -0,0 +1,89 @@ + +Bash (Terminal) +Assume your present working directory is $ ~/buffy +Make two directories inside ~/buffy: scoobies and vamps + +> mkdir scoobies +> mkdir vamps + +Make files in scoobies named buffy.txt, giles.txt and angel.txt + +> cd scoobies +> touch buffy.txt +> touch giles.txt +> touch angel.txt + +Copy angel.txt into the vamps directory +> cp angle.txt \vamps + +Delete the vamps directory and everything inside it +> rm -rf vamps + +JS Variables +Assign the string "Jack" to a variable called captain +> var captain = "jack"; + +Using the captain variable, use string concatenation to form the string "Oh Jack, my Jack!", assigning it to a variable named phrase + +> var captain = "Oh Jack, my Jack!"; +> var phrase = captain + + +JS Conditionals +var souls = 3; +var lifeRafts = 2; +Write an if statement that console.logs "SOS!" if there are more souls than lifeRafts + +if (lifeRafts > souls){ + console.log(souls); +} +else { + console.log(lifeRafts); +} + +Data Structures - JS Arrays +Create an array named weekend with just 'Saturday' in it +> var weekend = ['Saturday']; + +Add 'Sunday' to the end of the weekend array +> var array = weekend.push('Sunday'); + + +Add 'Friday' to the front to the front of the weekend array +> var array = weekend.unshift('Friday'); + +Access 'Saturday' in the array and assign to a variable named day +> var array = weekend[0]; +> var name = day; + +Remove 'Friday' from the array +> var array = weekend.shift(); + +Data Structures - JS Objects +Write an object literal named brain having a property of energyLevel with a value of 10 as a number + +> var brain = { + energyLevel: 10, +}; + +Assign the property of energyLevel to a variable named energy + +>var brain = { + energyLevel: 10, +}; + + +Add a dream property to the brain object that holds the string 'electric sheep' + + +Add a dayDream property to the brain object that holds the object { lunch: ['burger', 'beer'] } + + +Add another element pudding to the lunch array inside the brain object + + +JS Functions +Write a function to return the area of a rectangle (the product of its length and its width) + + +Invoke the function with 3 and 4 as arguments and save it to a variable named result