├── Basic Algorithm Scripting ├── 01 convert celsius to fahrenheit │ ├── convertcalsiustofahrenheit.md │ └── index.js ├── 02 reverse a string │ ├── index.js │ └── reverse.md ├── 03 factorialize a number │ ├── factorial.md │ └── index.js ├── 04 find the longest word in a string │ ├── index.js │ └── longestword.md ├── 05 return largest numbers in arrays │ ├── index.js │ └── largestnumberinarrays.md ├── 06 confirm the ending │ ├── confirmtheending.md │ └── index.js ├── 07 repeat a string │ ├── index.js │ └── repeatastring.md ├── 08 truncate a string │ ├── index.js │ └── truncatesstring.md ├── 09 finders keepers │ ├── finderskeepers.md │ └── index.js ├── 10 boo who │ ├── boowho.md │ └── index.js ├── 11 title case sentence │ ├── index.js │ └── titlecasesentence.md ├── 12 slice and splice │ ├── index.js │ └── sliceandsplice.md ├── 13 falsy bouncer │ ├── falsybouncer.md │ └── index.js ├── 14 where do i belong │ ├── index.js │ └── where go i belong.md ├── 15 mutations │ ├── index.js │ └── mutations.md └── 16 chunky monkey │ ├── chunky monkey.md │ └── index.js ├── Basic Data Structures ├── 01 use an array to store a collection of data │ ├── index.js │ └── usearraytostoredata.md ├── 02 access an array's content using bracket notation │ ├── accessarrayusingbracketnotation.md │ └── index.js ├── 03 add items to an array with push() and unshift() │ ├── additem.md │ └── index.js ├── 04 remove items from an array with pop and shift │ ├── index.js │ └── removeitem.md ├── 05 remove item using splice │ ├── index.js │ └── splice.md ├── 06 add items using splice │ ├── additemusingsplice.md │ └── index.js ├── 07 copy array items using slice │ ├── index.js │ └── slice.md ├── 08 copy an array with the spread operator │ ├── index.js │ └── spread.md ├── 09 combine array with the spread operator │ ├── combinearrayusnigspread.md │ └── index.js ├── 10 check for the presence of an element with indexof │ ├── index.js │ └── indexof.md ├── 11 iterate through all in array items using for loops │ ├── forloop.md │ └── index.js ├── 12 create comlex multidimentioanl arrays │ ├── index.js │ └── multidimentioanlarrays.md ├── 13 add key-value pairs to Js objects │ ├── addkeyvalue.md │ └── index.js ├── 14 modify an object nested within an object │ ├── index.js │ └── modifyobject.md ├── 15 access property names with brackets notation │ ├── bracketsnotation.md │ └── index.js ├── 16 use the delete keyword to remove object properties │ ├── delete.md │ └── index.js ├── 17 check if an object has a property │ ├── hasproperty.md │ └── index.js ├── 18 iterate through the keys of an object with a for...in statement │ ├── forin.md │ └── index.js ├── 19 genrate an array of all object keys with object.keys │ ├── index.js │ └── object.keys.md └── 20 modify an array stored in an object │ ├── index.js │ └── modifyarray.md ├── Basic JavaScript ├── 001 comment your Js code │ ├── comment.md │ └── index.js ├── 002 declare Js variable │ ├── index.js │ └── variable.md ├── 003 storing value │ ├── index.js │ └── store.md ├── 004 initialize variable │ ├── index.js │ └── initialize.md ├── 005 understanding uninitialized variables │ ├── index.js │ └── uninitialized.md ├── 006 case sensitivity in variables │ ├── casesensitive.md │ └── index.js ├── 007 add two numbers │ ├── add.md │ └── index.js ├── 008 substract two numbers │ ├── index.js │ └── substract.md ├── 009 multiply two numbers │ ├── index.js │ └── multiply.md ├── 010 divide one number by another │ ├── divide.md │ └── index.js ├── 011 increment a number with Js │ ├── increment.md │ └── index.js ├── 012 decrement number with Js │ ├── decrement.md │ └── index.js ├── 013 create decimal number with Js │ ├── decimal.md │ └── index.js ├── 014 multiply two decimals with Js │ ├── index.js │ └── multiplydecimal.md ├── 015 divide one decimal number by another │ ├── dividedecimal.md │ └── index.js ├── 016 finiding a remember in Js │ ├── index.js │ └── remainer.md ├── 017 compound assignment with addition │ ├── compundassignment.md │ └── index.js ├── 018 compund assignment with substraction │ ├── compoundsubstraction.md │ └── index.js ├── 019 compound assignment with multiplication │ ├── compundmultiplication.md │ └── index.js ├── 020 compound assignment with division │ ├── compounddivision.md │ └── index.js ├── 021 declare string variable │ ├── index.js │ └── string.md ├── 022 escaping literal quotes in string │ ├── escapeliteral.md │ └── index.js ├── 023 quoting strings with single quote │ ├── index.js │ └── singlequote.md ├── 024 escape sequences in strings │ ├── escapesequences.md │ └── index.js ├── 025 concatenating strings with plus operator │ ├── concatenatewithplus.md │ └── index.js ├── 026 concatenating string with plus equal operator │ ├── cancatenatewithplusequal.md │ └── index.js ├── 027 constructing string with variables │ ├── index.js │ └── stringvariables.md ├── 028 appending variables to strings │ ├── appendvariables.md │ └── index.js ├── 029 find length of string │ ├── findlength.md │ └── index.js ├── 030 use bracket notation to find first char in a string │ ├── bracketnotation.md │ └── index.js ├── 031 understanding string immutability │ ├── index.js │ └── stringimmutability.md ├── 032 use bracket notation to find nth char in string │ ├── index.js │ └── nthchar.md ├── 033 use bracket notation to find the last char in string │ ├── index.js │ └── lastchar.md ├── 034 use bracket notation to find nth char in string │ ├── index.js │ └── nthchar.md ├── 035 world blanks │ ├── index.js │ └── worldbanks.md ├── 036 store multiple value in one variable using arrays │ ├── arrays.md │ └── index.js ├── 037 next one array within another array │ ├── index.js │ └── nestarray.md ├── 038 access array data with indexes │ ├── accessarray.md │ └── index.js ├── 039 modify array data with indexes │ ├── index.js │ └── modifyarray.md ├── 040 access multidimensional arrays with indexes │ ├── index.js │ └── multidimensionalarray.md ├── 041 manipulate array with push() │ ├── index.js │ └── push.md ├── 042 manipulate arrays with pop() │ ├── index.js │ └── pop.md ├── 043 manipulate array with shift() │ ├── index.js │ └── shift.md ├── 044 manipulate array with unshift() │ ├── index.js │ └── unshift.md ├── 045 shopping list │ ├── index.js │ └── shoppinglist.md ├── 046 write reusable Js with functions │ ├── function.md │ └── index.js ├── 047 passing values to functions with arguments │ ├── index.js │ └── passvalues.md ├── 048 global scope and functions │ ├── globalscope.md │ └── index.js ├── 049 local scope and functions │ ├── index.js │ └── localscope.md ├── 050 global vs local scope in functions │ ├── globalvslocal.md │ └── index.js ├── 051 return a value from function with return │ ├── index.js │ └── returnvalue.md ├── 052 understanding undefined value returned from function │ ├── index.js │ └── undefinedretrun.md ├── 053 assignment with a returned value │ ├── assignedreturnvalue.md │ └── index.js ├── 054 stand in line │ ├── index.js │ └── standinline.md ├── 055 understanding boolean values │ ├── boolean.md │ └── index.js ├── 056 use conditional logic with if statements │ ├── ifstatements.md │ └── index.js ├── 057 comparison with equilty operator │ ├── equalityoperator.md │ └── index.js ├── 058 comparison with the strict equality operator │ ├── index.js │ └── strictequality.md ├── 059 practice comparing different values │ ├── comparediffvalues.md │ └── index.js ├── 060 comparison with the inequality operator │ ├── index.js │ └── inequality.md ├── 061 comparison with strict inequality operator │ ├── index.js │ └── strictinequality.md ├── 062 comparison with the greater than operator │ ├── greaterthanoperator.md │ └── index.js ├── 063 comparison with the greter then or equal │ ├── greaterthanequal.md │ └── index.js ├── 064 comparison with the less than operator │ ├── index.js │ └── lessthan.md ├── 065 comparison with less than or equal to operator │ ├── index.js │ └── lessthanorequal.md ├── 066 comparison with the logical and operator │ ├── index.js │ └── logicalandoperator.md ├── 067 comparison with logical or operator │ ├── index.js │ └── logicaloroperator.md ├── 068 introducing else statements │ ├── elsestatement.md │ └── index.js ├── 069 introducing else if statements │ ├── elseifstatements.md │ └── index.js ├── 070 logical order in if else statements │ ├── ifelsestatements.md │ └── index.js ├── 071 chaining if else statements │ ├── chainifelse.md │ └── index.js ├── 072 golf code │ ├── golfindex.md │ └── index.js ├── 073 selecting from many options with switch statements │ ├── index.js │ └── switch.md ├── 074 adding default options in switch statements │ ├── index.js │ └── switchdefaultstatement.md ├── 075 multiple identical options in switch statements │ ├── index.js │ └── multipleoptionsswitch.md ├── 076 replacing if else chains with switch │ ├── index.js │ └── replaceifelse.md ├── 077 returing boolean values from functions │ ├── index.js │ └── returnboolean.md ├── 078 return early patterns for functions │ ├── index.js │ └── returnpattern.md ├── 080 build javascript objects │ ├── buildobjects.md │ ├── counting-card.js │ └── index.js ├── 081 accessing object properties with dot notation │ ├── accesswithdot.md │ └── index.js ├── 082 accessing object properties with bracket notaion │ ├── accessingwithbrackets.md │ └── index.js ├── 083 accessing object properties with variables │ ├── accesswithvariables.md │ └── index.js ├── 084 updating object properties │ ├── index.js │ └── updateproperties.md ├── 085 add new properties to a Js object │ ├── addnewproperty.md │ └── index.js ├── 086 delete properties from Js object │ ├── deleteproperties.md │ └── index.js ├── 087 using objects for lookups │ ├── index.js │ └── objectsforlookups.md ├── 088 testing objects for properties │ ├── index.js │ └── objectforproperties.md ├── 089 manipulating complex objects │ ├── index.js │ └── manipulatecomplexobject.md ├── 090 accessing nested objects │ ├── accessnestesobject.md │ └── index.js ├── 091 accessing nested arrays │ ├── accessnestedarays.md │ └── index.js ├── 092 record collection │ ├── index.js │ └── recordcollection.md ├── 093 iterate with Js while loops │ ├── index.js │ └── while.md ├── 094 iterate with Js for loops │ ├── for.md │ └── index.js ├── 095 iterate odd number with for loop │ ├── index.js │ └── iterateforodd.md ├── 096 count backwards with a for loop │ ├── countbackwards.md │ └── index.js ├── 097 iterate through an array with a for loop │ ├── arrayforloop.md │ └── index.js ├── 098 nesting loops │ ├── index.js │ └── nestingloops.md ├── 099 iterate with Js do while loop │ ├── dowhile.md │ └── index.js ├── 100 perfect lookup │ ├── index.js │ └── perfectloopup.md ├── 101 generate random fractions with Js │ ├── generatefraction.md │ └── index.js ├── 102 generate random whole number with Js │ ├── index.js │ └── randomwholenumber.md ├── 103 generate randome whole numbers within a range │ ├── index.js │ └── wholenumberrange.md ├── 104 use the parseint function │ ├── index.js │ └── parseint.md ├── 105 use the parseInt function with radix │ ├── index.js │ └── parseintradix.md ├── 106 use the conditional(ternary) opertor │ ├── index.js │ └── ternary.md └── 107 use multiple conditional operators │ ├── index.js │ └── multipleternary.md ├── Certificate └── FreeCodeCamp Certificaite.png ├── Debugging ├── 01 use the Js console to check the value of a variable │ ├── index.js │ └── usejsconsole.md ├── 02 understanding the diff bw freecodecamp and browser console │ ├── index.js │ └── understanddiff.md ├── 03 use typeof to check the type of a variable │ ├── index.js │ └── typeof.md ├── 04 catch misspelled variable and function names │ ├── catchmisspelledwords.md │ └── index.js ├── 05 catch unclosed paraentheses, brackets, braces and quotes │ ├── catchunclosed.md │ └── index.js ├── 06 catch mixed usage of single and double quotes │ ├── catchquotes.md │ └── index.js ├── 07 catch use of assignment operator instead of equality operator │ ├── catchassignment.md │ └── index.js ├── 08 catch missing open and close parenthesis after a function call │ ├── catchparenthesis.md │ └── index.js ├── 09 catch arguments passed in wrong order when calling a function │ ├── catcharguments.md │ └── index.js ├── 10 catch off by one errors when using indexing │ ├── catchoffbyone.md │ └── index.js ├── 11 use caution when reinitializing variables inside a loop │ ├── index.js │ └── usecautioninloops.md └── 12 prevent infinte loops with valid terminal condition │ ├── index.js │ └── preventinfinteloops.md ├── ES6 ├── 01 explore differences between the var and let keywords │ ├── index.js │ └── letvar.md ├── 02 compare scopes of the var and let keywords │ ├── compareletvarscope.md │ └── index.js ├── 03 declare a read only variable with const keyword │ ├── const.md │ └── index.js ├── 04 mutate an array declared with const │ ├── index.js │ └── mutatearraywithconst.md ├── 05 prevent object mutation │ ├── index.js │ └── objectmutaion.md ├── 06 use arrow functions to write concise anonymous functions │ ├── arrow.md │ └── index.js ├── 07 write arrow functions woth parameters │ ├── arrowfuntionswithparameter.md │ └── index.js ├── 08 write higher order arrow functions │ ├── highrerorderarrow.md │ └── index.js ├── 09 set default parameters for your functions │ ├── defaultparameters.md │ └── index.js ├── 10 use the rest operator with funtion parameters │ ├── index.js │ └── restoperator.md ├── 11 use spread operator to evaluate arrays in-place │ ├── index.js │ └── spreadoperator.md ├── 12 use destructing assignment to assign variables from objects │ ├── destructingassignment.md │ └── index.js ├── 13 use destruturing assignment to assign variables from nested objects │ ├── index.js │ └── nesteddestructing.md ├── 14 use destructing assignments to assign varibles from arrays │ ├── destructingassignfromarrays.md │ └── index.js ├── 15 use destructing assignment with the rest operator to reassign array elements │ ├── index.js │ └── reassignusingdestructing.md ├── 16 use destructing assignment to pass an object as a funtion parameters │ ├── index.js │ └── passobject.md ├── 17 create strings using template literals │ ├── index.js │ └── stringliterals.md ├── 18 write concise object literal declarations using simple fields │ ├── index.js │ └── objectliterals.md ├── 19 write concise declarative functions with es6 │ ├── declartivefunctions.md │ └── index.js ├── 20 use class syntax to define constructor function │ ├── class.md │ └── index.js ├── 21 use getters and setters to control access to an object │ ├── gettersetters.md │ └── index.js ├── 22 understand differences between import and require │ ├── diffbwimportrequire.md │ └── index.js ├── 23 use export to reuse a code block │ ├── export.md │ └── index.js ├── 24 use * to import everyting from a file │ ├── *import.md │ └── index.js ├── 25 create an export fallback with export default │ ├── exportfallback.md │ └── index.js └── 26 import a default export │ ├── importdefault.md │ └── index.js ├── Functional Programming ├── 01 learn about functional programming │ ├── functionprogramming.md │ └── index.js ├── 02 understand functional programming terminology │ ├── index.js │ └── understandfunctionalprogramming.md ├── 03 understand the hazards of using imperative code │ ├── imperativecode.md │ └── index.js ├── 04 avoid mutations and side effects using functional programming │ ├── avoidmutations.md │ └── index.js ├── 05 pass arguments to avoid external dependence in a function │ ├── index.js │ └── passarguments.md ├── 06 refactor global variables out of function │ ├── index.js │ └── refactorglobalvariables.md ├── 07 use map method to extract data from array │ ├── index.js │ └── map.md ├── 08 implement map on a prototype │ ├── implementmap.md │ └── index.js ├── 09 use the filter method to extract data from an array │ ├── filter.md │ └── index.js ├── 10 implement the filter method on a prototype │ ├── filterprototype.md │ └── index.js ├── 11 return part of an array using slice method │ ├── index.js │ └── returnpartofarray.md ├── 12 remove elements from an array using slice instead of splice │ ├── index.js │ └── removeelementsusingslice.md ├── 13 combine two arrays using concat method │ ├── concat.md │ └── index.js ├── 14 add elements to the end of an array using concat instead of push │ ├── addelementsattheend.md │ └── index.js ├── 15 use the reduce method to analyze data │ ├── index.js │ └── reduce.md ├── 16 sort an array alphabetically using the sort method │ ├── index.js │ └── sortalphabetically.md ├── 17 return a sorted array without changing the original array │ ├── index.js │ └── returnsortedarraywithoutchange.md ├── 18 split a string into an array using the split method │ ├── index.js │ └── split.md ├── 19 combine an array into a string using the join method │ ├── index.js │ └── join.md ├── 20 apply functional programming to convert string to url slugs │ ├── index.js │ └── stringtourl.md ├── 21 use the every method to check that evert element in an array meets a criteria │ ├── every.md │ └── index.js ├── 22 use the some method to check that any elements in an array meet a crietria │ ├── index.js │ └── some.md └── 23 introduction to currying and partial appllication │ ├── curryingandpartial.md │ └── index.js ├── Intermediate Algorithm Scripting ├── 01 sum of all numbers in a range │ ├── indes.js │ └── sumofallnumbers.md ├── 02 diff two arrays │ ├── diffarray.md │ └── index.js ├── 03 seek and destroy │ ├── index.js │ └── seekanddestroy.md ├── 04 wherefore atr thou │ ├── index.js │ └── whereforeatrthou.md ├── 05 spinal tap case │ ├── index.js │ └── spinaltapcase.md ├── 06 pig latin │ ├── index.js │ └── piglatin.md ├── 07 search and replace │ ├── index.js │ └── searchandreplace.md ├── 08 dna pairing │ ├── dnapairing.md │ └── index.js ├── 09 missing letters │ ├── index.js │ └── missingletter.md ├── 10 sorted union │ ├── index.js │ └── sortedunion.md ├── 11 convert html entities │ ├── converthtmlentites.md │ └── index.js ├── 12 sum all odd fibonacci numbers │ ├── index.js │ └── sumofoddfibinaccinumbers.md ├── 13 sum of all primes │ ├── index.js │ └── sumofallprimers.md ├── 14 smallest common multiple │ ├── index.js │ └── smallestcommonmultiple.md ├── 15 drop it │ ├── dropit.md │ └── index.js ├── 16 steamroller │ ├── index.js │ └── steamroller.md ├── 17 binary agents │ ├── binary.md │ └── index.js ├── 18 everything be true │ ├── everythingbetrue.md │ └── index.js ├── 19 argument optional │ ├── argumentoptional.md │ └── index.js ├── 20 make a person │ ├── index.js │ └── makeaperson.md ├── 21 map and debris │ ├── index.js │ └── mapanddebris.md ├── 22 shortest substring │ └── index.js └── 23 buying show tickets │ └── index.js ├── JavaScript Algorithms and Data Structures Projects ├── 01 palindrome checker │ ├── index.js │ └── palindromechecker.md ├── 02 roman numeral converter │ ├── index.js │ └── romannumeralconverter.md ├── 03 caesars cipher │ ├── caesarscipher.md │ └── index.js ├── 04 telephone number validator │ ├── index.js │ └── telephonenumbervalidatore.md └── 05 cash register │ ├── cashregister.md │ └── index.js ├── Object Oriented Programming ├── 01 create a basic Js object │ ├── basicobject.md │ └── index.js ├── 02 use dot notation to access the properties of an object │ ├── dotnotation.md │ └── index.js ├── 03 create a method on an object │ ├── createamethod.md │ └── index.js ├── 04 make code more reusable with the this keyword │ ├── index.js │ └── thiskeyword.md ├── 05 define a constructor function │ ├── constructor.md │ └── index.js ├── 06 use a constructor to create objects │ ├── createobject.md │ └── index.js ├── 07 extend constructor to receive arguments │ ├── index.js │ └── receivearguments.md ├── 08 verify an object constructor with instanceof │ ├── index.js │ └── instanceof.md ├── 09 understand own properties │ ├── index.js │ └── ownproperties.md ├── 10 use prototype properties to reduce duplicate code │ ├── index.js │ └── prototypeproperties.md ├── 11 iterate over all properties │ ├── index.js │ └── iterate.md ├── 12 understand the constructor property │ ├── constructorproperty.md │ └── index.js ├── 13 change the prototype to a new object │ ├── changeprototype.md │ └── index.js ├── 14 remember to set the constructor property when changing the prototype │ ├── index.js │ └── setconstructorproperty.md ├── 15 understand where an object prototype come from │ ├── index.js │ └── objectprototype.md ├── 16 understand the prototype chain │ ├── index.js │ └── prototypechain.md ├── 17 use inheritance so you don't repeat yourself │ ├── index.js │ └── inheritance.md ├── 18 inherit behaviors from a supertype │ ├── index.js │ └── inheritbehaviors.md ├── 19 set the child prototype to an instance of parent │ ├── index.js │ └── setchildprototype.md ├── 20 reset an inherited constructor property │ ├── index.js │ └── resetinheritedproperty.md ├── 21 add methods after inheritance │ ├── addmethod.md │ └── index.js ├── 22 ovveride inherited methods │ ├── index.js │ └── overrideinheritedmethods.md ├── 23 use a mixin to add common behavior between unrelated objects │ ├── index.js │ └── mixins.md ├── 24 use closure to protect properties within an object from being modified externally │ ├── closure.md │ └── index.js ├── 25 understand the immediately inoked function expression(iife) │ ├── iife.md │ └── index.js └── 26 use an iife to create a module │ ├── iifemodule.md │ └── index.js ├── README.md └── Regular Expressions ├── 01 using the test method ├── index.js └── testmethod.md ├── 02 match literal strings ├── index.js └── matchliteral.md ├── 03 match a literal string with different possibilites ├── index.js └── matchliteral.md ├── 04 ignore case while matching ├── ignorecase.md └── index.js ├── 05 extract matches ├── extractmatches.md └── index.js ├── 06 find more than the first match ├── findmorematches.md └── index.js ├── 07 match anything with wildcard reriod ├── index.js └── matchanything.md ├── 08 match signle character with multiple possobilites ├── index.js └── matchsingle.md ├── 09 match letter of the alphabet ├── index.js └── matchalphabet.md ├── 10 match numbers and letters of alphabet ├── index.js └── matchnumbers.md ├── 11 match single characters not specified ├── index.js └── matchsinglechar.md ├── 12 match characters that occure one or more times ├── index.js └── matchmore.md ├── 13 match characters that occur zero or more times ├── index.js └── matchzeroormore.md ├── 14 find characters with lazy matching ├── index.js └── lazymatching.md ├── 15 find one or more criminals in a hunt ├── index.js └── oneormorecriminals.md ├── 16 match beginning string patterns ├── index.js └── matchbeginningstring.md ├── 17 match ending string patterns ├── index.js └── matchendingstring.md ├── 18 match all letters and numbers ├── index.js └── matchalllettersnumbers.md ├── 19 match everything but letters and numbers ├── index.js └── matcheverythingbutlettersandnumbers.md ├── 20 match all numbers ├── index.js └── matchallnumbers.md ├── 21 match all non numbers ├── index.js └── matchnonnumbers.md ├── 22 restrict possible usernames ├── index.js └── restrictusernames.md ├── 23 match white spaces ├── index.js └── matchwhitespace.md ├── 24 match non whitespace characters ├── index.js └── matchnonspace.md ├── 25 specify upper and lower number of matches ├── index.js └── upperlowermatches.md ├── 26 specify only the lower number of matches ├── index.js └── onlylowermatches.md ├── 27 specify exact number of matches ├── exactmatches.md └── index.js ├── 28 check for all or none ├── checkallornone.md └── index.js ├── 29 positive ans negative looahead ├── index.js └── positivenegativelookahead.md ├── 30 reuse patterns using capture groups ├── index.js └── reusepatterncapturegroups.md ├── 31 use capture groups to search and replace ├── capturegroupsearchreplace.md └── index.js └── 32 remove whitespce from start and end ├── index.js └── removewhitespace.md /Basic Algorithm Scripting/01 convert celsius to fahrenheit/convertcalsiustofahrenheit.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times _9/5_, plus _32_. 4 | 5 | You are given a variable `celsius` representing a temperature in Celsius. Use the variable `fahrenheit` already defined and assign it the Fahrenheit temperature equivalent to the given Celsius temperature. Use the algorithm mentioned above to help convert the Celsius temperature to Fahrenheit. 6 | 7 | Don't worry too much about the function and return statements as they will be covered in future challenges. For now, only use operators that you have already learned. 8 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/01 convert celsius to fahrenheit/index.js: -------------------------------------------------------------------------------- 1 | function convertToF(celsius) { 2 | let fahrenheit; 3 | fahrenheit = (9 / 5) * celsius + 32; 4 | return fahrenheit; 5 | } 6 | 7 | console.log(convertToF(-40)); 8 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/02 reverse a string/index.js: -------------------------------------------------------------------------------- 1 | function reverseString(str) { 2 | /** 3 | * Reversing string using built-in functions 4 | */ 5 | return str 6 | .split("") 7 | .reverse() 8 | .join(""); 9 | 10 | /** 11 | * Reversing string using decrementing for loop 12 | */ 13 | // let newString = ""; 14 | // for (let i = str.length - 1; i >= 0; i--) { 15 | // newString += str[i]; 16 | // } 17 | 18 | // return newString; 19 | 20 | /** 21 | * Reversing string with recursion 22 | */ 23 | // if (str === "") return str; 24 | // else return reverseString(str.substr(1) + str.charAt(0)); 25 | } 26 | 27 | console.log(reverseString("hello")); 28 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/02 reverse a string/reverse.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Reverse the provided string. 4 | 5 | You may need to turn the string into an array before you can reverse it. 6 | 7 | Your result must be a string. 8 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/03 factorialize a number/factorial.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Return the factorial of the provided integer. 4 | 5 | If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n. 6 | 7 | Factorials are often represented with the shorthand notation n! 8 | 9 | For example: `5! = 1 * 2 * 3 * 4 * 5 = 120` 10 | 11 | Only integers greater than or equal to zero will be supplied to the function. 12 | 13 | Remember to use Read-Search-Ask if you get stuck. Write your own code. 14 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/03 factorialize a number/index.js: -------------------------------------------------------------------------------- 1 | function factorialize(num) { 2 | if (num === 0) { 3 | return 1; 4 | } else { 5 | return num * factorialize(num - 1); 6 | } 7 | } 8 | 9 | console.log(factorialize(3)); 10 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/04 find the longest word in a string/longestword.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: :headphones: 2 | 3 | Return the length of the longest word in the provided sentence. 4 | 5 | Your response should be a number. 6 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/05 return largest numbers in arrays/largestnumberinarrays.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: :headphones: 2 | 3 | Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays. 4 | 5 | Remember, you can iterate through an array with a simple for loop, and access each member with array syntax `arr[i]`. 6 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/06 confirm the ending/confirmtheending.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Check if a string (first argument, str) ends with the given target string (second argument, target). 4 | 5 | This challenge can be solved with the `.endsWith()` method, which was introduced in ES2015. But for the purpose of this challenge, we would like you to use one of the JavaScript substring methods instead. 6 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/06 confirm the ending/index.js: -------------------------------------------------------------------------------- 1 | // First method using endsWith() 2 | 3 | // function confirmEnding(str, target) { 4 | // // "Never give up and good luck will find you." 5 | // // -- Falcor 6 | // console.log(str.endsWith(target)); 7 | // return str.endsWith(target); 8 | // } 9 | 10 | // confirmEnding("Bastian", "n"); 11 | 12 | // Second method split() 13 | 14 | // console.log(str.substr(-2)); // la 15 | 16 | function confirmEnding(string, target) { 17 | if (string.substr(-target.length) === target) { 18 | return true; 19 | } else { 20 | return false; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/07 repeat a string /index.js: -------------------------------------------------------------------------------- 1 | function repeatStringNumTimes(str, num) { 2 | // repeat after me 3 | let repeatedString = ""; 4 | if (num < 0) { 5 | return ""; 6 | } else { 7 | while (num > 0) { 8 | repeatedString += str; 9 | num--; 10 | } 11 | } 12 | return repeatedString; 13 | } 14 | 15 | repeatStringNumTimes("abcd", 2); 16 | 17 | // Second method using repeat() 18 | 19 | // function repeatStringNumTimes(string, num) { 20 | // if (num < 0) { 21 | // return ""; 22 | // } else { 23 | // return string.repeat(num); 24 | // } 25 | // } 26 | 27 | // console.log(repeatStringNumTimes("abc", 4)); 28 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/07 repeat a string /repeatastring.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Repeat a given string `str` (first argument) for `num` times (second argument). Return an empty string if `num` is not a positive number. -------------------------------------------------------------------------------- /Basic Algorithm Scripting/08 truncate a string/truncatesstring.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a ... ending. 4 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/09 finders keepers/finderskeepers.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Create a function that looks through an array (first argument) and returns the first element in the array that passes a truth test (second argument). If no element passes the test, return `undefined`. 4 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/09 finders keepers/index.js: -------------------------------------------------------------------------------- 1 | function findElement(arr, func) { 2 | let num = 0; 3 | 4 | for (var i = 0; i < arr.length; i++) { 5 | num = arr[i]; 6 | if (func(num)) { 7 | return num; 8 | } 9 | } 10 | 11 | return undefined; 12 | } 13 | 14 | findElement([1, 2, 3, 4], num => num % 2 === 0); 15 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/10 boo who/boowho.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Check if a value is classified as a boolean primitive. Return true or false. 4 | 5 | Boolean primitives are true and false. 6 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/10 boo who/index.js: -------------------------------------------------------------------------------- 1 | function booWho(bool) { 2 | // What is the new fad diet for ghost developers? The Boolean. 3 | if (typeof bool === "boolean") { 4 | return true; 5 | } 6 | return false; 7 | } 8 | 9 | console.log(booWho(true)); 10 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/11 title case sentence/titlecasesentence.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case. 4 | 5 | For the purpose of this exercise, you should also capitalize connecting words like "the" and "of". -------------------------------------------------------------------------------- /Basic Algorithm Scripting/12 slice and splice/index.js: -------------------------------------------------------------------------------- 1 | function frankenSplice(arr1, arr2, n) { 2 | // It's alive. It's alive! 3 | let localArray = arr2.slice(); 4 | for (let i = 0; i < arr1.length; i++) { 5 | localArray.splice(n, 0, arr1[i]); 6 | n++; 7 | } 8 | return localArray; 9 | } 10 | 11 | frankenSplice([1, 2, 3], [4, 5, 6], 1); 12 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/12 slice and splice/sliceandsplice.md: -------------------------------------------------------------------------------- 1 | :coffee: :headphones: :purple_heart: 2 | 3 | You are given two arrays and an index. 4 | 5 | Use the array methods slice and splice to copy each element of the first array into the second array, in order. 6 | 7 | Begin inserting elements at index n of the second array. 8 | 9 | Return the resulting array. The input arrays should remain the same after the function runs. -------------------------------------------------------------------------------- /Basic Algorithm Scripting/13 falsy bouncer/falsybouncer.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Remove all falsy values from an array. 4 | 5 | Falsy values in JavaScript are `false`, `null`, `0`, `""`, `undefined`, and `NaN`. 6 | 7 | Hint: Try converting each value to a Boolean. -------------------------------------------------------------------------------- /Basic Algorithm Scripting/13 falsy bouncer/index.js: -------------------------------------------------------------------------------- 1 | function bouncer(arr) { 2 | // Don't show a false ID to this bouncer. 3 | let falsyArr = [0, "", NaN, undefined, false, null]; 4 | return arr.filter(ele => !falsyArr.includes(ele)); 5 | } 6 | 7 | console.log(bouncer([7, "ate", "", false, 9, 0])); 8 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/14 where do i belong/index.js: -------------------------------------------------------------------------------- 1 | function getIndexToIns(arr, num) { 2 | // Find my place in this sorted array. 3 | arr.sort(function(a, b) { 4 | return a - b; 5 | }); 6 | for (let i = 0; i < arr.length; i++) { 7 | if (arr[i] >= num) { 8 | console.log(i); 9 | return i; 10 | } 11 | } 12 | return arr.length; 13 | } 14 | 15 | getIndexToIns([40, 45, 60], 50); 16 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/14 where do i belong/where go i belong.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Return the lowest index at which a value (second argument) should be inserted into an array (first argument) once it has been sorted. The returned value should be a number. 4 | 5 | For example, `getIndexToIns([1,2,3,4], 1.5)` should return `1` because it is greater than `1` (index 0), but less than `2` (index 1). 6 | 7 | Likewise, `getIndexToIns([20,3,5], 19)` should return `2` because once the array has been sorted it will look like `[3,5,20]` and `19` is less than `20` (index 2) and greater than `5` (index 1). 8 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/15 mutations/index.js: -------------------------------------------------------------------------------- 1 | function mutation(arr) { 2 | return arr[1].toLowerCase() 3 | .split('') 4 | .every(function(letter) { 5 | return arr[0].toLowerCase() 6 | .indexOf(letter) != -1; 7 | }); 8 | } 9 | console.log(mutation(["hello", "hey"])); 10 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/15 mutations/mutations.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array. 4 | 5 | For example, `["hello", "Hello"]`, should return true because all of the letters in the second string are present in the first, ignoring case. 6 | 7 | The arguments `["hello", "hey"]` should return false because the string "hello" does not contain a "y". 8 | 9 | Lastly, ["Alien", "line"], should return true because all of the letters in "line" are present in "Alien". 10 | 11 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/16 chunky monkey/chunky monkey.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array. 4 | -------------------------------------------------------------------------------- /Basic Algorithm Scripting/16 chunky monkey/index.js: -------------------------------------------------------------------------------- 1 | function chunkArrayInGroups(arr, size) { 2 | 3 | let temp = []; 4 | let result = []; 5 | 6 | for (let a = 0; a < arr.length; a++) { 7 | if (a % size !== size - 1) 8 | temp.push(arr[a]); 9 | else { 10 | temp.push(arr[a]); 11 | result.push(temp); 12 | temp = []; 13 | } 14 | } 15 | 16 | if (temp.length !== 0) 17 | result.push(temp); 18 | return result; 19 | } 20 | 21 | chunkArrayInGroups(["a", "b", "c", "d"], 2); -------------------------------------------------------------------------------- /Basic Data Structures/01 use an array to store a collection of data/index.js: -------------------------------------------------------------------------------- 1 | let yourArray = [true, 11, "Sam", undefined, {name: "Sam", age: 21}]; // change this line -------------------------------------------------------------------------------- /Basic Data Structures/02 access an array's content using bracket notation/index.js: -------------------------------------------------------------------------------- 1 | let myArray = ["a", "b", "c", "d"]; 2 | // change code below this line 3 | myArray[1] = "boy" 4 | //change code above this line 5 | console.log(myArray); -------------------------------------------------------------------------------- /Basic Data Structures/03 add items to an array with push() and unshift()/index.js: -------------------------------------------------------------------------------- 1 | function mixedNumbers(arr) { 2 | // change code below this line 3 | arr.unshift("I", 2, "three"); 4 | arr.push(7, "VIII", 9); 5 | // change code above this line 6 | return arr; 7 | } 8 | 9 | // do not change code below this line 10 | console.log(mixedNumbers(["IV", 5, "six"])); 11 | -------------------------------------------------------------------------------- /Basic Data Structures/04 remove items from an array with pop and shift/index.js: -------------------------------------------------------------------------------- 1 | function popShift(arr) { 2 | let popped = arr.pop(); // change this line 3 | let shifted = arr.shift(); // change this line 4 | return [shifted, popped]; 5 | } 6 | 7 | // do not change code below this line 8 | console.log(popShift(['challenge', 'is', 'not', 'complete'])); -------------------------------------------------------------------------------- /Basic Data Structures/05 remove item using splice/index.js: -------------------------------------------------------------------------------- 1 | function sumOfTen(arr) { 2 | // change code below this line 3 | console.log(arr.splice(1, 2)); 4 | // change code above this line 5 | return arr.reduce((a, b) => a + b); 6 | } 7 | 8 | // do not change code below this line 9 | console.log(sumOfTen([2, 5, 1, 5, 2, 1])); 10 | -------------------------------------------------------------------------------- /Basic Data Structures/06 add items using splice/index.js: -------------------------------------------------------------------------------- 1 | function htmlColorNames(arr) { 2 | // change code below this line 3 | console.log(arr.splice(0, 2, "DarkSalmon", "BlanchedAlmond")); 4 | // change code above this line 5 | return arr; 6 | } 7 | 8 | // do not change code below this line 9 | console.log( 10 | htmlColorNames([ 11 | "DarkGoldenRod", 12 | "WhiteSmoke", 13 | "LavenderBlush", 14 | "PaleTurqoise", 15 | "FireBrick" 16 | ]) 17 | ); 18 | -------------------------------------------------------------------------------- /Basic Data Structures/07 copy array items using slice/index.js: -------------------------------------------------------------------------------- 1 | function forecast(arr) { 2 | // change code below this line 3 | return arr.slice(2,4); 4 | } 5 | 6 | // do not change code below this line 7 | console.log(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms'])); -------------------------------------------------------------------------------- /Basic Data Structures/08 copy an array with the spread operator/index.js: -------------------------------------------------------------------------------- 1 | function copyMachine(arr, num) { 2 | let newArr = []; 3 | while (num >= 1) { 4 | // change code below this line 5 | newArr.push([...arr]); 6 | // change code above this line 7 | num--; 8 | } 9 | return newArr; 10 | } 11 | 12 | // change code here to test different cases: 13 | console.log(copyMachine([true, false, true], 2)); 14 | -------------------------------------------------------------------------------- /Basic Data Structures/09 combine array with the spread operator/index.js: -------------------------------------------------------------------------------- 1 | function spreadOut() { 2 | let fragment = ['to', 'code']; 3 | let sentence = ['learning', ...fragment, 'is', 'fun']; // change this line 4 | return sentence; 5 | } 6 | 7 | // do not change code below this line 8 | console.log(spreadOut()); -------------------------------------------------------------------------------- /Basic Data Structures/10 check for the presence of an element with indexof/index.js: -------------------------------------------------------------------------------- 1 | function quickCheck(arr, elem) { 2 | // change code below this line 3 | let index = arr.indexOf(elem); 4 | if (index >= 0) return true; 5 | else return false; 6 | // change code above this line 7 | } 8 | 9 | // change code here to test different cases: 10 | console.log(quickCheck(["squash", "onions", "shallots"], "mushrooms")); 11 | -------------------------------------------------------------------------------- /Basic Data Structures/11 iterate through all in array items using for loops/index.js: -------------------------------------------------------------------------------- 1 | function filteredArray(arr, elem) { 2 | let newArr = []; 3 | // change code below this line 4 | for (let i = 0; i < arr.length; i++) { 5 | if (arr[i].indexOf(elem) == -1) { 6 | //Checks every parameter for the element and if is NOT there continues the code 7 | newArr.push(arr[i]); //Inserts the element of the array in the new filtered array 8 | } 9 | } 10 | // change code above this line 11 | return newArr; 12 | } 13 | 14 | // change code here to test different cases: 15 | console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 3, 9]], 3)); 16 | -------------------------------------------------------------------------------- /Basic Data Structures/12 create comlex multidimentioanl arrays/index.js: -------------------------------------------------------------------------------- 1 | let myNestedArray = [ 2 | // change code below this line 3 | ['unshift', false, 1, 2, 3, 'complex', 'nested'], 4 | ['loop', 'shift', 6, 7, 1000, 'method'], 5 | ['concat', false, true, 'spread', 'array',["deep"]], 6 | ['mutate', 1327.98, 'splice', 'slice', 'push', [["deeper"]]], 7 | ['iterate', 1.3849, 7, '8.4876', 'arbitrary', 'depth', [[["deepest"]]] ] 8 | // change code above this line 9 | ]; -------------------------------------------------------------------------------- /Basic Data Structures/13 add key-value pairs to Js objects/index.js: -------------------------------------------------------------------------------- 1 | let foods = { 2 | apples: 25, 3 | oranges: 32, 4 | plums: 28 5 | }; 6 | 7 | // change code below this line 8 | foods.bananas = 13; 9 | foods.grapes = 35; 10 | foods.strawberries = 27; 11 | // change code above this line 12 | 13 | console.log(foods); 14 | -------------------------------------------------------------------------------- /Basic Data Structures/14 modify an object nested within an object/index.js: -------------------------------------------------------------------------------- 1 | let userActivity = { 2 | id: 23894201352, 3 | date: 'January 1, 2017', 4 | data: { 5 | totalUsers: 51, 6 | online: 42 7 | } 8 | }; 9 | 10 | // change code below this line 11 | userActivity.data.online = 45; 12 | // change code above this line 13 | 14 | console.log(userActivity); -------------------------------------------------------------------------------- /Basic Data Structures/15 access property names with brackets notation/index.js: -------------------------------------------------------------------------------- 1 | let foods = { 2 | apples: 25, 3 | oranges: 32, 4 | plums: 28, 5 | bananas: 13, 6 | grapes: 35, 7 | strawberries: 27 8 | }; 9 | // do not change code above this line 10 | 11 | function checkInventory(scannedItem) { 12 | // change code below this line 13 | return foods[scannedItem]; 14 | } 15 | 16 | // change code below this line to test different cases: 17 | console.log(checkInventory("apples")); 18 | -------------------------------------------------------------------------------- /Basic Data Structures/16 use the delete keyword to remove object properties/index.js: -------------------------------------------------------------------------------- 1 | let foods = { 2 | apples: 25, 3 | oranges: 32, 4 | plums: 28, 5 | bananas: 13, 6 | grapes: 35, 7 | strawberries: 27 8 | }; 9 | 10 | // change code below this line 11 | delete foods.oranges; 12 | delete foods.plums; 13 | delete foods.strawberries; 14 | // change code above this line 15 | 16 | console.log(foods); 17 | -------------------------------------------------------------------------------- /Basic Data Structures/17 check if an object has a property/index.js: -------------------------------------------------------------------------------- 1 | let users = { 2 | Alan: { 3 | age: 27, 4 | online: true 5 | }, 6 | Jeff: { 7 | age: 32, 8 | online: true 9 | }, 10 | Sarah: { 11 | age: 48, 12 | online: true 13 | }, 14 | Ryan: { 15 | age: 19, 16 | online: true 17 | } 18 | }; 19 | 20 | function isEveryoneHere(obj) { 21 | // change code below this line 22 | if (users.hasOwnProperty("Alan", "Jeff", "Sarah", "Ryan")) { 23 | return true; 24 | } 25 | return false; 26 | // change code above this line 27 | } 28 | 29 | console.log(isEveryoneHere(users)); 30 | -------------------------------------------------------------------------------- /Basic Data Structures/18 iterate through the keys of an object with a for...in statement/index.js: -------------------------------------------------------------------------------- 1 | //Not completed 2 | 3 | let users = { 4 | Alan: { 5 | age: 27, 6 | online: false 7 | }, 8 | Jeff: { 9 | age: 32, 10 | online: true 11 | }, 12 | Sarah: { 13 | age: 48, 14 | online: false 15 | }, 16 | Ryan: { 17 | age: 19, 18 | online: true 19 | } 20 | }; 21 | 22 | function countOnline(obj) { 23 | // change code below this line 24 | let onlUsers = 0; 25 | for (let user in obj) { 26 | if (obj[user].online === true) { 27 | onlUsers++; 28 | } 29 | } 30 | return onlUsers; 31 | // change code above this line 32 | } 33 | 34 | console.log(countOnline(users)); 35 | -------------------------------------------------------------------------------- /Basic Data Structures/19 genrate an array of all object keys with object.keys/index.js: -------------------------------------------------------------------------------- 1 | let users = { 2 | Alan: { 3 | age: 27, 4 | online: false 5 | }, 6 | Jeff: { 7 | age: 32, 8 | online: true 9 | }, 10 | Sarah: { 11 | age: 48, 12 | online: false 13 | }, 14 | Ryan: { 15 | age: 19, 16 | online: true 17 | } 18 | }; 19 | 20 | function getArrayOfUsers(obj) { 21 | // change code below this line 22 | return Object.keys(obj); 23 | // change code above this line 24 | } 25 | 26 | console.log(getArrayOfUsers(users)); 27 | -------------------------------------------------------------------------------- /Basic Data Structures/19 genrate an array of all object keys with object.keys/object.keys.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | We can also generate an array which contains all the keys stored in an object using the `Object.keys()` method and passing in an object as the argument. This will return an array with strings representing each property in the object. Again, there will be no specific order to the entries in the array. 4 | 5 | :fire: 6 | 7 | Finish writing the `getArrayOfUsers` function so that it returns an array containing all the properties in the object it receives as an argument. 8 | -------------------------------------------------------------------------------- /Basic Data Structures/20 modify an array stored in an object/index.js: -------------------------------------------------------------------------------- 1 | let user = { 2 | name: "Kenneth", 3 | age: 28, 4 | data: { 5 | username: "kennethCodesAllDay", 6 | joinDate: "March 26, 2016", 7 | organization: "freeCodeCamp", 8 | friends: ["Sam", "Kira", "Tomo"], 9 | location: { 10 | city: "San Francisco", 11 | state: "CA", 12 | country: "USA" 13 | } 14 | } 15 | }; 16 | 17 | function addFriend(userObj, friend) { 18 | // change code below this line 19 | return userObj.data.friends.push(friend); 20 | return userObj.data.friends; 21 | // change code above this line 22 | } 23 | 24 | console.log(addFriend(user, "Pete")); 25 | -------------------------------------------------------------------------------- /Basic JavaScript/001 comment your Js code/index.js: -------------------------------------------------------------------------------- 1 | // This is in-line comment. 2 | 3 | /* 4 | This is multi-line comment 5 | */ 6 | -------------------------------------------------------------------------------- /Basic JavaScript/002 declare Js variable/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourName; 3 | 4 | // Declare myName below this line 5 | var myName; 6 | -------------------------------------------------------------------------------- /Basic JavaScript/003 storing value/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | var a; 3 | var b = 2; 4 | 5 | // Only change code below this line 6 | a = 7; 7 | b = a; 8 | -------------------------------------------------------------------------------- /Basic JavaScript/003 storing value/store.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | In JavaScript, you can store a value in a variable with the assignment operator. 4 | ```javascript 5 | myVariable = 5; 6 | ``` 7 | This assigns the Number value 5 to myVariable. 8 | 9 | Assignment always goes from right to left. Everything to the right of the = operator is resolved before the value is assigned to the variable to the left of the operator. 10 | 11 | ```javascript 12 | myVar = 5; 13 | myNum = myVar; 14 | ``` 15 | This assigns 5 to myVar and then resolves myVar to 5 again and assigns it to myNum. 16 | 17 | :fire: 18 | 19 | Assign the value 7 to variable a. 20 | 21 | Assign the contents of a to variable b. -------------------------------------------------------------------------------- /Basic JavaScript/004 initialize variable/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourVar = 19; 3 | 4 | // Only change code below this line 5 | var a = 9; 6 | -------------------------------------------------------------------------------- /Basic JavaScript/004 initialize variable/initialize.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | It is common to _initialize_ a variable to an initial value in the same line as it is declared. 4 | 5 | ```javascript 6 | var myVar = 0; 7 | ``` 8 | 9 | Creates a new variable called `myVar` and assigns it an initial value of `0`. 10 | 11 | :fire: 12 | 13 | Define a variable `a` with `var` and initialize it to a value of `9`. 14 | -------------------------------------------------------------------------------- /Basic JavaScript/005 understanding uninitialized variables/index.js: -------------------------------------------------------------------------------- 1 | // Initialize these three variables 2 | var a = 5; 3 | var b = 10; 4 | var c = "I am a"; 5 | 6 | // Do not change code below this line 7 | 8 | a = a + 1; 9 | b = b + 5; 10 | c = c + " String!"; 11 | -------------------------------------------------------------------------------- /Basic JavaScript/005 understanding uninitialized variables/uninitialized.md: -------------------------------------------------------------------------------- 1 | :coffee: :thumbsup: 2 | 3 | When JavaScript variables are declared, they have an initial value of `undefined`. If you do a mathematical operation on an undefined variable your result will be `NaN` which means "Not a Number". If you concatenate a string with an undefined variable, you will get a literal string of "undefined". 4 | 5 | :fire: 6 | 7 | Initialize the three variables `a`, `b`, and `c` with `5`, `10`, and `"I am a"` respectively so that they will not be `undefined`. 8 | -------------------------------------------------------------------------------- /Basic JavaScript/006 case sensitivity in variables/index.js: -------------------------------------------------------------------------------- 1 | // Declarations 2 | var studlyCapVar; 3 | var properCamelCase; 4 | var titleCaseOver; 5 | 6 | // Assignments 7 | studlyCapVar = 10; 8 | properCamelCase = "A String"; 9 | titleCaseOver = 9000; 10 | -------------------------------------------------------------------------------- /Basic JavaScript/007 add two numbers/add.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | `Number` is a data type in JavaScript which represents numeric data. 4 | 5 | Now let's try to add two numbers using JavaScript. 6 | 7 | JavaScript uses the `+` symbol as addition operation when placed between two numbers. 8 | 9 | Example 10 | 11 | ```javascript 12 | myVar = 5 + 10; // assigned 15 13 | ``` 14 | 15 | :fire: 16 | 17 | Change the `0` so that `sum` will equal `20`. 18 | -------------------------------------------------------------------------------- /Basic JavaScript/007 add two numbers/index.js: -------------------------------------------------------------------------------- 1 | var sum = 10 + 10; 2 | -------------------------------------------------------------------------------- /Basic JavaScript/008 substract two numbers/index.js: -------------------------------------------------------------------------------- 1 | var difference = 45 - 33; 2 | console.log(difference); 3 | -------------------------------------------------------------------------------- /Basic JavaScript/008 substract two numbers/substract.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | We can also subtract one number from another. 4 | 5 | JavaScript uses the `-` symbol for subtraction. 6 | 7 | Example 8 | 9 | ```javascript 10 | myVar = 12 - 6; // assigned 6 11 | ``` 12 | 13 | :fire: 14 | 15 | Change the `0` so the `difference` is `12`. 16 | -------------------------------------------------------------------------------- /Basic JavaScript/009 multiply two numbers/index.js: -------------------------------------------------------------------------------- 1 | var product = 8 * 10; 2 | -------------------------------------------------------------------------------- /Basic JavaScript/009 multiply two numbers/multiply.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | We can also multiply one number by another. 4 | 5 | JavaScript uses the `*` symbol for multiplication of two numbers. 6 | 7 | Example 8 | 9 | ```javascript 10 | myVar = 13 * 13; // assigned 169 11 | ``` 12 | 13 | :fire: 14 | 15 | Change the `0` so that `product` will equal `80`. 16 | -------------------------------------------------------------------------------- /Basic JavaScript/010 divide one number by another/divide.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | We can also divide one number by another. 4 | 5 | JavaScript uses the `/` symbol for division. 6 | 7 | Example 8 | 9 | ```javascript 10 | myVar = 16 / 2; // assigned 8 11 | ``` 12 | 13 | :fire: 14 | 15 | Change the `0` so that the `quotient` is equal to `2`. 16 | -------------------------------------------------------------------------------- /Basic JavaScript/010 divide one number by another/index.js: -------------------------------------------------------------------------------- 1 | var quotient = 66 / 33; 2 | -------------------------------------------------------------------------------- /Basic JavaScript/011 increment a number with Js/increment.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | You can easily _increment_ or add one to a variable with the `++` operator. 4 | 5 | ```javascript 6 | i++; 7 | ``` 8 | 9 | is the equivalent of 10 | 11 | ```javascript 12 | i = i + 1; 13 | ``` 14 | 15 | **note** 16 | 17 | The entire line becomes `i++;,` eliminating the need for the equal sign. 18 | 19 | :fire: 20 | 21 | Change the code to use the `++` operator on `myVar`. 22 | 23 | **Hint** 24 | 25 | Learn more about [Arithmetic operators - Increment (++)](). 26 | -------------------------------------------------------------------------------- /Basic JavaScript/011 increment a number with Js/index.js: -------------------------------------------------------------------------------- 1 | var myVar = 87; 2 | 3 | // Only change code below this line 4 | myVar++; 5 | -------------------------------------------------------------------------------- /Basic JavaScript/012 decrement number with Js/decrement.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | You can easily _decrement_ or decrease a variable by one with the `--` operator. 4 | 5 | ```javascript 6 | i--; 7 | ``` 8 | 9 | is the equivalent of 10 | 11 | ```javascript 12 | i = i - 1; 13 | ``` 14 | 15 | **Note** 16 | The entire line becomes `i--;,` eliminating the need for the equal sign. 17 | 18 | :fire: 19 | 20 | Change the code to use the `--` operator on myVar. 21 | -------------------------------------------------------------------------------- /Basic JavaScript/012 decrement number with Js/index.js: -------------------------------------------------------------------------------- 1 | var myVar = 11; 2 | 3 | // Only change code below this line 4 | myVar--; 5 | -------------------------------------------------------------------------------- /Basic JavaScript/013 create decimal number with Js/decimal.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | We can store decimal numbers in variables too. Decimal numbers are sometimes referred to as _floating point_ numbers or floats. 4 | 5 | **Note** 6 | Not all real numbers can accurately be represented in floating point. This can lead to rounding errors. Details Here. 7 | 8 | :fire: 9 | 10 | Create a variable `myDecimal` and give it a decimal value with a fractional part (e.g. `5.7`). 11 | -------------------------------------------------------------------------------- /Basic JavaScript/013 create decimal number with Js/index.js: -------------------------------------------------------------------------------- 1 | var ourDecimal = 5.7; 2 | 3 | // Only change code below this line 4 | 5 | var myDecimal = 11.12; 6 | -------------------------------------------------------------------------------- /Basic JavaScript/014 multiply two decimals with Js/index.js: -------------------------------------------------------------------------------- 1 | var product = 2.0 * 2.0 + 1.0; 2 | 3 | -------------------------------------------------------------------------------- /Basic JavaScript/014 multiply two decimals with Js/multiplydecimal.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | In JavaScript, you can also perform calculations with decimal numbers, just like whole numbers. 4 | 5 | Let's multiply two decimals together to get their product. 6 | 7 | :fire: 8 | 9 | Change the `0.0` so that `product` will equal `5.0`. 10 | -------------------------------------------------------------------------------- /Basic JavaScript/015 divide one decimal number by another/dividedecimal.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Now let's divide one decimal by another. 4 | 5 | :fire: 6 | 7 | Change the `0.0` so that `quotient` will equal to `2.2`. 8 | -------------------------------------------------------------------------------- /Basic JavaScript/015 divide one decimal number by another/index.js: -------------------------------------------------------------------------------- 1 | var quotient = 4.0 / 2.0 + 0.2; // Fix this line 2 | 3 | console.log(quotient); 4 | -------------------------------------------------------------------------------- /Basic JavaScript/016 finiding a remember in Js/index.js: -------------------------------------------------------------------------------- 1 | // Only change code below this line 2 | 3 | var remainder = 11 % 3; 4 | -------------------------------------------------------------------------------- /Basic JavaScript/016 finiding a remember in Js/remainer.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The _remainder_ operator `%` gives the remainder of the division of two numbers. 4 | 5 | **Example** 6 | 7 | ```javascript 8 | 5 % 2 = 1 because 9 | Math.floor(5 / 2) = 2 (Quotient) 10 | 2 * 2 = 4 11 | 5 - 4 = 1 (Remainder) 12 | ``` 13 | 14 | **Usage** 15 | In mathematics, a number can be checked to be even or odd by checking the remainder of the division of the number by 2. 16 | 17 | 17 % 2 = 1 (17 is Odd) 18 | 48 % 2 = 0 (48 is Even) 19 | 20 | **Note** 21 | The remainder operator is sometimes incorrectly referred to as the "modulus" operator. It is very similar to modulus, but does not work properly with negative numbers. 22 | 23 | Set remainder equal to the remainder of 11 divided by 3 using the remainder (%) operator. 24 | -------------------------------------------------------------------------------- /Basic JavaScript/017 compound assignment with addition/compundassignment.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | In programming, it is common to use assignments to modify the contents of a variable. Remember that everything to the right of the equals sign is evaluated first, so we can say: 4 | 5 | ```javascript 6 | myVar = myVar + 5; 7 | ``` 8 | 9 | to add `5 to`myVar`. Since this is such a common pattern, there are operators which do both a mathematical operation and assignment in one step. 10 | 11 | One such operator is the += operator. 12 | 13 | ```javascript 14 | var myVar = 1; 15 | myVar += 5; 16 | console.log(myVar); // Returns 6 17 | ``` 18 | 19 | :fire: 20 | 21 | Convert the assignments for `a`, `b`, and `c` to use the `+=` operator. 22 | -------------------------------------------------------------------------------- /Basic JavaScript/017 compound assignment with addition/index.js: -------------------------------------------------------------------------------- 1 | var a = 3; 2 | var b = 17; 3 | var c = 12; 4 | 5 | // Only modify code below this line 6 | 7 | a += 12; 8 | b += 9; 9 | c += 7; 10 | -------------------------------------------------------------------------------- /Basic JavaScript/018 compund assignment with substraction/compoundsubstraction.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Like the `+=` operator, `-=` subtracts a number from a variable. 4 | 5 | ```javascript 6 | myVar = myVar - 5; 7 | ``` 8 | 9 | will subtract `5` from `myVar`. This can be rewritten as: 10 | 11 | ```javascript 12 | myVar -= 5; 13 | ``` 14 | 15 | :fire: 16 | 17 | Convert the assignments for `a`, `b`, and `c` to use the `-=` operator. 18 | -------------------------------------------------------------------------------- /Basic JavaScript/018 compund assignment with substraction/index.js: -------------------------------------------------------------------------------- 1 | var a = 11; 2 | var b = 9; 3 | var c = 3; 4 | 5 | // Only modify code below this line 6 | 7 | a -= 6; 8 | b -= 15; 9 | c -= 1; 10 | -------------------------------------------------------------------------------- /Basic JavaScript/019 compound assignment with multiplication/compundmultiplication.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The `*=` operator multiplies a variable by a number. 4 | 5 | ```javascript 6 | myVar = myVar * 5; 7 | ``` 8 | 9 | will multiply `myVar` by `5`. This can be rewritten as: 10 | 11 | ```javascript 12 | myVar *= 5; 13 | ``` 14 | 15 | :fire: 16 | 17 | Convert the assignments for `a`, `b`, and `c` to use the `*=` operator. 18 | -------------------------------------------------------------------------------- /Basic JavaScript/019 compound assignment with multiplication/index.js: -------------------------------------------------------------------------------- 1 | var a = 5; 2 | var b = 12; 3 | var c = 4.6; 4 | 5 | // Only modify code below this line 6 | 7 | a *= 5; 8 | b *= 3; 9 | c *= 10; 10 | -------------------------------------------------------------------------------- /Basic JavaScript/020 compound assignment with division/compounddivision.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The `/=` operator divides a variable by another number. 4 | 5 | ```javascript 6 | myVar = myVar / 5; 7 | ``` 8 | 9 | Will divide `myVar` by `5`. This can be rewritten as: 10 | 11 | ```javascript 12 | myVar /= 5; 13 | ``` 14 | 15 | :fire: 16 | 17 | Convert the assignments for `a`, `b`, and `c` to use the `/=` operator. 18 | -------------------------------------------------------------------------------- /Basic JavaScript/020 compound assignment with division/index.js: -------------------------------------------------------------------------------- 1 | var a = 48; 2 | var b = 108; 3 | var c = 33; 4 | 5 | // Only modify code below this line 6 | 7 | a /= 12; 8 | b /= 4; 9 | c /= 11; 10 | -------------------------------------------------------------------------------- /Basic JavaScript/021 declare string variable/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var firstName = "Alan"; 3 | var lastName = "Turing"; 4 | 5 | // Only change code below this line 6 | 7 | var myFirstName = "Ganesh"; 8 | var myLastName = "Pawar"; 9 | -------------------------------------------------------------------------------- /Basic JavaScript/021 declare string variable/string.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Previously we have used the code 4 | 5 | ```javascript 6 | var myName = "your name"; 7 | ``` 8 | 9 | `"your name"` is called a _string literal_. It is a string because it is a series of zero or more characters enclosed in single or double quotes. 10 | 11 | :fire: 12 | 13 | Create two new `string` variables: `myFirstName` and `myLastName` and assign them the values of your first and last name, respectively. 14 | -------------------------------------------------------------------------------- /Basic JavaScript/022 escaping literal quotes in string/index.js: -------------------------------------------------------------------------------- 1 | var myStr = 'I am a \"double quoted\" string inside \"double quotes\".'; // Change this line 2 | console.log(myStr); -------------------------------------------------------------------------------- /Basic JavaScript/023 quoting strings with single quote/index.js: -------------------------------------------------------------------------------- 1 | var myStr = 'Link'; 2 | -------------------------------------------------------------------------------- /Basic JavaScript/024 escape sequences in strings/index.js: -------------------------------------------------------------------------------- 1 | var myStr = "FirstLine\n\t\\SecondLine\nThirdLine"; // Change this line 2 | -------------------------------------------------------------------------------- /Basic JavaScript/025 concatenating strings with plus operator/concatenatewithplus.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | In JavaScript, when the `+` operator is used with a `String` value, it is called the concatenation operator. You can build a new string out of other strings by _concatenating_ them together. 4 | 5 | Example 6 | 7 | ```javascript 8 | "My name is Alan," + " I concatenate."; 9 | ``` 10 | 11 | Note 12 | 13 | Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself. 14 | 15 | :fire: 16 | 17 | Build `myStr` from the strings `"This is the start. "` and `"This is the end."` using the `+` operator. 18 | -------------------------------------------------------------------------------- /Basic JavaScript/025 concatenating strings with plus operator/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourStr = "I come first. " + "I come second."; 3 | 4 | // Only change code below this line 5 | 6 | var myStr = "This is the start. " + "This is the end."; 7 | -------------------------------------------------------------------------------- /Basic JavaScript/026 concatenating string with plus equal operator/cancatenatewithplusequal.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | We can also use the `+=` operator to _concatenate_ a string onto the end of an existing string variable. This can be very helpful to break a long string over several lines. 4 | 5 | Note 6 | Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself. 7 | 8 | :fire: 9 | 10 | Build `myStr` over several lines by concatenating these two strings: `"This is the first sentence. "` and `"This is the second sentence."` using the `+=` operator. Use the `+=` operator similar to how it is shown in the editor. Start by assigning the first string to `myStr`, then add on the second string. 11 | -------------------------------------------------------------------------------- /Basic JavaScript/026 concatenating string with plus equal operator/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourStr = "I come first. "; 3 | ourStr += "I come second."; 4 | 5 | // Only change code below this line 6 | 7 | var myStr = "This is the first sentence. "; 8 | myStr += "This is the second sentence."; 9 | -------------------------------------------------------------------------------- /Basic JavaScript/027 constructing string with variables/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourName = "freeCodeCamp"; 3 | var ourStr = "Hello, our name is " + ourName + ", how are you?"; 4 | 5 | // Only change code below this line 6 | var myName = "Ganesh"; 7 | var myStr = "My name is " + myName + " and I am well!"; 8 | 9 | -------------------------------------------------------------------------------- /Basic JavaScript/027 constructing string with variables/stringvariables.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Sometimes you will need to build a string, Mad Libs style. By using the concatenation operator (`+`), you can insert one or more variables into a string you're building. 4 | 5 | :fire: 6 | 7 | Set `myName` to a string equal to your name and build `myStr` with `myName` between the strings `"My name is "` and `" and I am well!"` 8 | -------------------------------------------------------------------------------- /Basic JavaScript/028 appending variables to strings/appendvariables.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Just as we can build a string over multiple lines out of string _literals_, we can also append variables to a string using the plus equals (`+=`) operator. 4 | 5 | :fire: 6 | 7 | Set `someAdjective` and append it to `myStr` using the `+=` operator. 8 | -------------------------------------------------------------------------------- /Basic JavaScript/028 appending variables to strings/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var anAdjective = "awesome!"; 3 | var ourStr = "freeCodeCamp is "; 4 | ourStr += anAdjective; 5 | 6 | // Only change code below this line 7 | 8 | var someAdjective = "awesome!"; 9 | var myStr = "Learning to code is "; 10 | myStr += someAdjective; 11 | 12 | console.log(myStr); 13 | -------------------------------------------------------------------------------- /Basic JavaScript/029 find length of string/findlength.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | You can find the length of a `String` value by writing `.length` after the string variable or string literal. 4 | 5 | ```javascript 6 | "Alan Peter".length; // 10 7 | ``` 8 | 9 | For example, if we created a variable `var firstName = "Charles"`, we could find out how long the string `"Charles"` is by using the `firstName.length` property. 10 | 11 | :fire: 12 | 13 | Use the .length property to count the number of characters in the lastName variable and assign it to lastNameLength. 14 | -------------------------------------------------------------------------------- /Basic JavaScript/029 find length of string/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var firstNameLength = 0; 3 | var firstName = "Ada"; 4 | 5 | firstNameLength = firstName.length; 6 | 7 | // Setup 8 | var lastNameLength = 0; 9 | var lastName = "Lovelace"; 10 | 11 | // Only change code below this line. 12 | 13 | lastNameLength = lastName.length; 14 | -------------------------------------------------------------------------------- /Basic JavaScript/030 use bracket notation to find first char in a string/bracketnotation.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | _Bracket notation_ is a way to get a character at a specific _index_ within a string. 4 | 5 | Most modern programming languages, like JavaScript, don't start counting at 1 like humans do. They start at 0. This is referred to as _Zero-based_ indexing. 6 | 7 | For example, the character at index 0 in the word "Charles" is "C". So if `var firstName = "Charles"`, you can get the value of the first letter of the string by using firstName[0]. 8 | 9 | :fire: 10 | 11 | Use _bracket notation_ to find the first character in the lastName variable and assign it to _firstLetterOfLastName_. 12 | 13 | Hint 14 | Try looking at the firstLetterOfFirstName variable declaration if you get stuck. 15 | -------------------------------------------------------------------------------- /Basic JavaScript/030 use bracket notation to find first char in a string/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var firstLetterOfFirstName = ""; 3 | var firstName = "Ada"; 4 | 5 | firstLetterOfFirstName = firstName[0]; 6 | 7 | // Setup 8 | var firstLetterOfLastName = ""; 9 | var lastName = "Lovelace"; 10 | 11 | // Only change code below this line 12 | firstLetterOfLastName = lastName[0]; 13 | -------------------------------------------------------------------------------- /Basic JavaScript/031 understanding string immutability/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | var myStr = "Jello World"; 3 | 4 | // Only change code below this line 5 | 6 | myStr = "Hello World"; // Fix Me 7 | -------------------------------------------------------------------------------- /Basic JavaScript/032 use bracket notation to find nth char in string/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var firstName = "Ada"; 3 | var secondLetterOfFirstName = firstName[1]; 4 | 5 | // Setup 6 | var lastName = "Lovelace"; 7 | 8 | // Only change code below this line. 9 | var thirdLetterOfLastName = lastName[2]; 10 | -------------------------------------------------------------------------------- /Basic JavaScript/032 use bracket notation to find nth char in string/nthchar.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | You can also use _bracket notation_ to get the character at other positions within a string. 4 | 5 | Remember that computers start counting at 0, so the first character is actually the zeroth character. 6 | 7 | :fire: 8 | 9 | Let's try to set _thirdLetterOfLastName_ to equal the third letter of the _lastName_ variable using bracket notation. 10 | 11 | Hint 12 | Try looking at the _secondLetterOfFirstName_ variable declaration if you get stuck. 13 | -------------------------------------------------------------------------------- /Basic JavaScript/033 use bracket notation to find the last char in string/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var firstName = "Ada"; 3 | var lastLetterOfFirstName = firstName[firstName.length - 1]; 4 | 5 | // Setup 6 | var lastName = "Lovelace"; 7 | 8 | // Only change code below this line. 9 | var lastLetterOfLastName = lastName[lastName.length - 1]; 10 | -------------------------------------------------------------------------------- /Basic JavaScript/033 use bracket notation to find the last char in string/lastchar.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | In order to get the last letter of a string, you can subtract one from the string's length. 4 | 5 | For example, if `var firstName = "Charles"`, you can get the value of the last letter of the string by using `firstName[firstName.length - 1]`. 6 | 7 | :fire: 8 | 9 | Use _bracket notation_ to find the last character in the `lastName` variable. 10 | 11 | Hint 12 | Try looking at the `lastLetterOfFirstName` variable declaration if you get stuck. 13 | -------------------------------------------------------------------------------- /Basic JavaScript/034 use bracket notation to find nth char in string/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var firstName = "Ada"; 3 | var thirdToLastLetterOfFirstName = firstName[firstName.length - 3]; 4 | 5 | // Setup 6 | var lastName = "Lovelace"; 7 | 8 | // Only change code below this line 9 | var secondToLastLetterOfLastName = lastName[lastName.length - 2]; 10 | -------------------------------------------------------------------------------- /Basic JavaScript/034 use bracket notation to find nth char in string/nthchar.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | You can use the same principle we just used to retrieve the last character in a string to retrieve the Nth-to-last character. 4 | 5 | For example, you can get the value of the third-to-last letter of the `var firstName = "Charles"` string by using `firstName[firstName.length - 3]` 6 | 7 | :fire: 8 | 9 | Use _bracket notation_ to find the second-to-last character in the `lastName` string. 10 | 11 | Hint 12 | Try looking at the `thirdToLastLetterOfFirstName` variable declaration if you get stuck. 13 | -------------------------------------------------------------------------------- /Basic JavaScript/035 world blanks/index.js: -------------------------------------------------------------------------------- 1 | function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) { 2 | // Your code below this line 3 | var result = 4 | "My " + 5 | myNoun + 6 | " name is tom. He is " + 7 | myAdjective + 8 | " and he can " + 9 | myVerb + 10 | " " + 11 | myAdverb + 12 | "."; 13 | 14 | // Your code above this line 15 | return result; 16 | } 17 | 18 | // Change the words here to test your function 19 | console.log(wordBlanks("dog", "big", "ran", "quickly")); 20 | -------------------------------------------------------------------------------- /Basic JavaScript/036 store multiple value in one variable using arrays/arrays.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | With JavaScript `array` variables, we can store several pieces of data in one place. 4 | 5 | You start an array declaration with an opening square bracket, end it with a closing square bracket, and put a comma between each entry, like this: 6 | 7 | ```javascript 8 | var sandwich = ["peanut butter", "jelly", "bread"]. 9 | ``` 10 | :fire: 11 | 12 | Modify the new array `myArray` so that it contains both a string and a number (in that order). 13 | 14 | Hint 15 | Refer to the example code in the text editor if you get stuck. 16 | -------------------------------------------------------------------------------- /Basic JavaScript/036 store multiple value in one variable using arrays/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourArray = ["John", 23]; 3 | 4 | // Only change code below this line. 5 | var myArray = ["Apple", 12, "Banana", 8]; 6 | -------------------------------------------------------------------------------- /Basic JavaScript/037 next one array within another array/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourArray = [["the universe", 42], ["everything", 101010]]; 3 | 4 | // Only change code below this line. 5 | var myArray = [["Apple", 12], ["Banana", 5]]; 6 | -------------------------------------------------------------------------------- /Basic JavaScript/037 next one array within another array/nestarray.md: -------------------------------------------------------------------------------- 1 | :coffe: 2 | 3 | You can also nest arrays within other arrays, like this: `[["Bulls", 23], ["White Sox", 45]]`. This is also called a _Multi-dimensional Array_. 4 | 5 | :fire: 6 | 7 | Create a nested array called `myArray`. 8 | -------------------------------------------------------------------------------- /Basic JavaScript/038 access array data with indexes/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourArray = [50, 60, 70]; 3 | var ourData = ourArray[0]; // equals 50 4 | 5 | // Setup 6 | var myArray = [50, 60, 70]; 7 | 8 | // Only change code below this line. 9 | var myData = myArray[0]; 10 | -------------------------------------------------------------------------------- /Basic JavaScript/039 modify array data with indexes/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourArray = [18, 64, 99]; 3 | ourArray[1] = 45; // ourArray now equals [18,45,99]. 4 | 5 | // Setup 6 | var myArray = [18, 64, 99]; 7 | 8 | // Only change code below this line. 9 | 10 | myArray[0] = 45; 11 | -------------------------------------------------------------------------------- /Basic JavaScript/039 modify array data with indexes/modifyarray.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Unlike strings, the entries of arrays are _mutable_ and can be changed freely. 4 | 5 | Example 6 | 7 | ```javascript 8 | var ourArray = [50, 40, 30]; 9 | ourArray[0] = 15; // equals [15,40,30] 10 | ``` 11 | 12 | Note 13 | 14 | There shouldn't be any spaces between the array name and the square brackets, like array [0]. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code. 15 | 16 | :fire: 17 | 18 | Modify the data stored at index `0` of `myArray` to a value of `45`s. 19 | -------------------------------------------------------------------------------- /Basic JavaScript/040 access multidimensional arrays with indexes/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | var myArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [[10, 11, 12], 13, 14]]; 3 | 4 | // Only change code below this line. 5 | var myData = myArray[2][1]; 6 | -------------------------------------------------------------------------------- /Basic JavaScript/041 manipulate array with push()/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourArray = ["Stimpson", "J", "cat"]; 3 | ourArray.push(["happy", "joy"]); 4 | // ourArray now equals ["Stimpson", "J", "cat", ["happy", "joy"]] 5 | 6 | // Setup 7 | var myArray = [["John", 23], ["cat", 2]]; 8 | 9 | // Only change code below this line. 10 | 11 | myArray.push(["dog", 3]); 12 | -------------------------------------------------------------------------------- /Basic JavaScript/041 manipulate array with push()/push.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | An easy way to append data to the end of an array is via the `push()` function. 4 | 5 | :zap: `.push()` takes one or more parameters and "pushes" them onto the end of the array. 6 | 7 | ```javascript 8 | var arr = [1, 2, 3]; 9 | arr.push(4); 10 | // arr is now [1,2,3,4] 11 | ``` 12 | 13 | :fire: 14 | 15 | Push `["dog", 3]` onto the end of the`myArray` variable. 16 | -------------------------------------------------------------------------------- /Basic JavaScript/042 manipulate arrays with pop()/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourArray = [1, 2, 3]; 3 | var removedFromOurArray = ourArray.pop(); 4 | // removedFromOurArray now equals 3, and ourArray now equals [1,2] 5 | 6 | // Setup 7 | var myArray = [["John", 23], ["cat", 2]]; 8 | 9 | // Only change code below this line. 10 | var removedFromMyArray = myArray.pop(); 11 | -------------------------------------------------------------------------------- /Basic JavaScript/042 manipulate arrays with pop()/pop.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Another way to change the data in an array is with the `.pop()` function. 4 | 5 | :zap: `.pop()` is used to "pop" a value off of the end of an array. We can store this "popped off" value by assigning it to a variable. In other words, `.pop()` removes the last element from an array and returns that element. 6 | 7 | Any type of entry can be "popped" off of an array - numbers, strings, even nested arrays. 8 | 9 | ```javascript 10 | var threeArr = [1, 4, 6]; 11 | var oneDown = threeArr.pop(); 12 | console.log(oneDown); // Returns 6 13 | console.log(threeArr); // Returns [1, 4] 14 | ``` 15 | 16 | :fire: 17 | 18 | Use the .pop() function to remove the last item from myArray, assigning the "popped off" value to removedFromMyArray. 19 | -------------------------------------------------------------------------------- /Basic JavaScript/043 manipulate array with shift()/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourArray = ["Stimpson", "J", ["cat"]]; 3 | var removedFromOurArray = ourArray.shift(); 4 | // removedFromOurArray now equals "Stimpson" and ourArray now equals ["J", ["cat"]]. 5 | 6 | // Setup 7 | var myArray = [["John", 23], ["dog", 3]]; 8 | 9 | // Only change code below this line. 10 | var removedFromMyArray = myArray.shift(); 11 | -------------------------------------------------------------------------------- /Basic JavaScript/043 manipulate array with shift()/shift.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | `pop()` always removes the last element of an array. What if you want to remove the first? 4 | 5 | That's where .shift() comes in. :zap: It works just like .pop(), except it removes the first element instead of the last. 6 | 7 | :fire: 8 | 9 | Use the `.shift()` function to remove the first item from `myArray`, assigning the "shifted off" value to `removedFromMyArray`. 10 | -------------------------------------------------------------------------------- /Basic JavaScript/044 manipulate array with unshift()/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourArray = ["Stimpson", "J", "cat"]; 3 | ourArray.shift(); // ourArray now equals ["J", "cat"] 4 | ourArray.unshift("Happy"); 5 | // ourArray now equals ["Happy", "J", "cat"] 6 | 7 | // Setup 8 | var myArray = [["John", 23], ["dog", 3]]; 9 | myArray.shift(); 10 | 11 | // Only change code below this line. 12 | 13 | myArray.unshift(["Paul", 35]); 14 | -------------------------------------------------------------------------------- /Basic JavaScript/044 manipulate array with unshift()/unshift.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Not only can you shift elements off of the beginning of an array, you can also unshift elements to the beginning of an array i.e. add elements in front of the array. 4 | 5 | .unshift() works exactly like .push(), but instead of adding the element at the end of the array, :zap: unshift() adds the element at the beginning of the array. 6 | 7 | :fire: 8 | 9 | Add `["Paul",35]` to the beginning of the `myArray` variable using `unshift()`. 10 | -------------------------------------------------------------------------------- /Basic JavaScript/045 shopping list/index.js: -------------------------------------------------------------------------------- 1 | var myList = []; 2 | 3 | myList.push(["Apple", 12]); 4 | myList.push(["Milk", 2]); 5 | myList.push(["Notebook", 6]); 6 | myList.push(["Oranges", 12]); 7 | myList.push(["Vegetables", 1]); 8 | myList.push(["Banana", 12]); 9 | 10 | 11 | -------------------------------------------------------------------------------- /Basic JavaScript/045 shopping list/shoppinglist.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Create a shopping list in the variable `myList`. The list should be a multi-dimensional array containing several sub-arrays. 4 | 5 | The first element in each sub-array should contain a string with the name of the item. The second element should be a number representing the quantity i.e. 6 | 7 | `["Chocolate Bar", 15]` 8 | 9 | There should be at least 5 sub-arrays in the list. 10 | -------------------------------------------------------------------------------- /Basic JavaScript/046 write reusable Js with functions/function.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | In JavaScript, we can divide up our code into reusable parts called functions. 4 | 5 | Here's an example of a function: 6 | 7 | ```javascript 8 | function functionName() { 9 | console.log("Hello World"); 10 | } 11 | ``` 12 | 13 | You can call or invoke this function by using its name followed by parentheses, like this: 14 | 15 | `functionName();` 16 | 17 | Each time the function is called it will print out the message `"Hello World"` on the dev console. All of the code between the curly braces will be executed every time the function is called. 18 | 19 | :fire: 20 | 21 | Create a function called `reusableFunction` which prints "Hi World" to the dev console. 22 | Call the function. 23 | -------------------------------------------------------------------------------- /Basic JavaScript/046 write reusable Js with functions/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | function ourReusableFunction() { 3 | console.log("Heyya, World"); 4 | } 5 | 6 | ourReusableFunction(); 7 | 8 | // Only change code below this line 9 | function reusableFunction() { 10 | console.log("Hi World"); 11 | } 12 | 13 | reusableFunction(); 14 | -------------------------------------------------------------------------------- /Basic JavaScript/047 passing values to functions with arguments/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | function ourFunctionWithArgs(a, b) { 3 | console.log(a - b); 4 | } 5 | ourFunctionWithArgs(10, 5); // Outputs 5 6 | 7 | // Only change code below this line. 8 | 9 | function functionWithArgs(a, b) { 10 | console.log(a + b); 11 | } 12 | 13 | functionWithArgs(3, 6); 14 | -------------------------------------------------------------------------------- /Basic JavaScript/048 global scope and functions/globalscope.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | In JavaScript, _scope_ refers to the visibility of variables. Variables which are defined outside of a function block have _Global_ scope. This means, they can be seen everywhere in your JavaScript code. 4 | 5 | Variables which are used without the var keyword are automatically created in the global scope. This can create unintended consequences elsewhere in your code or when running a function again. You should always declare your variables with var. 6 | 7 | :fire: 8 | 9 | Using `var`, declare a _global_ variable `myGlobal` outside of any function. Initialize it with a value of `10`. 10 | 11 | Inside function `fun1`, assign `5` to `oopsGlobal` without using the var keyword. 12 | -------------------------------------------------------------------------------- /Basic JavaScript/048 global scope and functions/index.js: -------------------------------------------------------------------------------- 1 | // Declare your variable here 2 | var myGlobal = 10; 3 | 4 | function fun1() { 5 | // Assign 5 to oopsGlobal Here 6 | oopsGlobal = 5; 7 | } 8 | 9 | // Only change code above this line 10 | function fun2() { 11 | var output = ""; 12 | if (typeof myGlobal != "undefined") { 13 | output += "myGlobal: " + myGlobal; 14 | } 15 | if (typeof oopsGlobal != "undefined") { 16 | output += " oopsGlobal: " + oopsGlobal; 17 | } 18 | console.log(output); 19 | } 20 | -------------------------------------------------------------------------------- /Basic JavaScript/049 local scope and functions/index.js: -------------------------------------------------------------------------------- 1 | function myLocalScope() { 2 | "use strict"; // you shouldn't need to edit this line 3 | var myVar; 4 | console.log(myVar); 5 | } 6 | myLocalScope(); 7 | 8 | // Run and check the console 9 | // myVar is not defined outside of myLocalScope 10 | // console.log(myVar); 11 | 12 | // Now remove the console log line to pass the test 13 | -------------------------------------------------------------------------------- /Basic JavaScript/049 local scope and functions/localscope.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Variables which are declared within a function, as well as the function parameters have local scope. That means, they are only visible within that function. 4 | 5 | Here is a function myTest with a local variable called loc. 6 | 7 | ```javascript 8 | function myTest() { 9 | var loc = "foo"; 10 | console.log(loc); 11 | } 12 | myTest(); // logs "foo" 13 | console.log(loc); // loc is not defined 14 | ``` 15 | 16 | loc is not defined outside of the function. 17 | 18 | :fire: 19 | 20 | Declare a local variable `myVar` inside `myLocalScope`. Run the tests and then follow the instructions commented out in the editor. 21 | 22 | Hint 23 | Refreshing the page may help if you get stuck. 24 | -------------------------------------------------------------------------------- /Basic JavaScript/050 global vs local scope in functions/globalvslocal.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | It is possible to have both _local_ and _global_ variables with the same name. :zap: When you do this, the local variable takes precedence over the global variable. 4 | 5 | In this example: 6 | 7 | ```javascript 8 | var someVar = "Hat"; 9 | function myFun() { 10 | var someVar = "Head"; 11 | return someVar; 12 | } 13 | ``` 14 | 15 | The function myFun will return "Head" because the local version of the variable is present. 16 | 17 | :fire: 18 | 19 | Add a local variable to `myOutfit` it function to override the value of `outerWear` with "sweater". 20 | -------------------------------------------------------------------------------- /Basic JavaScript/050 global vs local scope in functions/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | var outerWear = "T-Shirt"; 3 | 4 | function myOutfit() { 5 | // Only change code below this line 6 | 7 | var outerWear = "sweater"; 8 | 9 | // Only change code above this line 10 | return outerWear; 11 | } 12 | 13 | myOutfit(); 14 | -------------------------------------------------------------------------------- /Basic JavaScript/051 return a value from function with return/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | function minusSeven(num) { 3 | return num - 7; 4 | } 5 | 6 | // Only change code below this line 7 | 8 | function timesFive(a) { 9 | return a * 5; 10 | } 11 | 12 | console.log(minusSeven(10)); 13 | console.log(timesFive(4)); 14 | -------------------------------------------------------------------------------- /Basic JavaScript/051 return a value from function with return/returnvalue.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | We can pass values into a function with _arguments_. You can use a return statement to send a value back out of a function. 4 | 5 | Example 6 | 7 | ```javascript 8 | function plusThree(num) { 9 | return num + 3; 10 | } 11 | var answer = plusThree(5); // 8 12 | ``` 13 | 14 | `plusThree` takes an argument for num and returns a value equal to `num + 3`. 15 | 16 | :fire: 17 | 18 | Create a function `timesFive` that accepts one argument, multiplies it by `5`, and returns the new value. See the last line in the editor for an example of how you can test your timesFive function. 19 | -------------------------------------------------------------------------------- /Basic JavaScript/052 understanding undefined value returned from function/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var sum = 0; 3 | function addThree() { 4 | sum = sum + 3; 5 | } 6 | 7 | // Only change code below this line 8 | function addFive() { 9 | sum += 5; 10 | } 11 | 12 | // Only change code above this line 13 | var returnedValue = addFive(); 14 | -------------------------------------------------------------------------------- /Basic JavaScript/053 assignment with a returned value/assignedreturnvalue.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | If you'll recall from our discussion of _Storing Values with the Assignment Operator_, everything to the right of the equal sign is resolved before the value is assigned. This means we can take the return value of a function and assign it to a variable. 4 | 5 | Assume we have pre-defined a function `sum` which adds two numbers together, then: 6 | 7 | `ourSum = sum(5, 12);` 8 | 9 | will call `sum` function, which returns a value of `17` and assigns it to `ourSum` variable. 10 | 11 | :fire: 12 | 13 | Call the `processArg` function with an argument of `7` and assign its return value to the variable `processed`. 14 | -------------------------------------------------------------------------------- /Basic JavaScript/053 assignment with a returned value/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var changed = 0; 3 | 4 | function change(num) { 5 | return (num + 5) / 3; 6 | } 7 | 8 | changed = change(10); 9 | 10 | // Setup 11 | var processed = 0; 12 | 13 | function processArg(num) { 14 | return (num + 3) / 5; 15 | } 16 | 17 | // Only change code below this line 18 | processed = processArg(7); 19 | -------------------------------------------------------------------------------- /Basic JavaScript/054 stand in line/index.js: -------------------------------------------------------------------------------- 1 | function nextInLine(arr, item) { 2 | // Your code here 3 | 4 | arr.push(item); 5 | 6 | return arr.shift(); // Change this line 7 | } 8 | 9 | // Test Setup 10 | var testArr = [1, 2, 3, 4, 5]; 11 | 12 | // Display Code 13 | console.log("Before: " + JSON.stringify(testArr)); 14 | console.log(nextInLine(testArr, 6)); // Modify this line to test 15 | console.log("After: " + JSON.stringify(testArr)); 16 | -------------------------------------------------------------------------------- /Basic JavaScript/054 stand in line/standinline.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | :zap: In Computer Science a _queue_ is an abstract _Data Structure_ where items are kept in order. New items can be added at the back of the queue and old items are taken off from the front of the queue. 4 | 5 | Write a function `nextInLine` which takes an array (`arr`) and a number (`item`) as arguments. 6 | 7 | Add the number to the end of the array, then remove the first element of the array. 8 | 9 | The `nextInLine` function should then return the element that was removed. 10 | -------------------------------------------------------------------------------- /Basic JavaScript/055 understanding boolean values/boolean.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Another data type is the _Boolean_. `Booleans` may only be one of two values: `true` or `false`. They are basically little on-off switches, where true is "on" and false is "off." These two states are mutually exclusive. 4 | 5 | Note 6 | 7 | `Boolean` values are never written with quotes. The strings "true" and "false" are not Boolean and have no special meaning in JavaScript. 8 | 9 | :fire: 10 | 11 | Modify the `welcomeToBooleans` function so that it returns `true` instead of `false` when the run button is clicked. -------------------------------------------------------------------------------- /Basic JavaScript/055 understanding boolean values/index.js: -------------------------------------------------------------------------------- 1 | function welcomeToBooleans() { 2 | 3 | // Only change code below this line. 4 | 5 | return true; // Change this line 6 | 7 | // Only change code above this line. 8 | } -------------------------------------------------------------------------------- /Basic JavaScript/056 use conditional logic with if statements/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | function ourTrueOrFalse(isItTrue) { 3 | if (isItTrue) { 4 | return "Yes, it's true"; 5 | } 6 | return "No, it's false"; 7 | } 8 | 9 | // Setup 10 | function trueOrFalse(wasThatTrue) { 11 | // Only change code below this line. 12 | if (wasThatTrue) return "Yes, that was true"; 13 | else return "No, that was false"; 14 | 15 | // Only change code above this line. 16 | } 17 | 18 | // Change this value to test 19 | trueOrFalse(true); 20 | -------------------------------------------------------------------------------- /Basic JavaScript/057 comparison with equilty operator/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | function testEqual(val) { 3 | if (val == 12) { 4 | // Change this line 5 | return "Equal"; 6 | } 7 | return "Not Equal"; 8 | } 9 | 10 | // Change this value to test 11 | testEqual(10); 12 | -------------------------------------------------------------------------------- /Basic JavaScript/058 comparison with the strict equality operator/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | function testStrict(val) { 3 | if (val === 7) { // Change this line 4 | return "Equal"; 5 | } 6 | return "Not Equal"; 7 | } 8 | 9 | // Change this value to test 10 | testStrict(10); -------------------------------------------------------------------------------- /Basic JavaScript/058 comparison with the strict equality operator/strictequality.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Strict equality (`===`) is the counterpart to the equality operator (`==`). However, unlike the equality operator, which attempts to convert both values being compared to a common type, :zap: the strict equality operator does not perform a type conversion. 4 | 5 | If the values being compared have different types, they are considered unequal, and the strict equality operator will return false. 6 | 7 | Examples 8 | 9 | ```javascript 10 | 3 === 3; // true 11 | 3 === "3"; // false 12 | ``` 13 | 14 | In the second example, `3` is a `Number` type and `'3'` is a `String` type. 15 | 16 | :fire: 17 | 18 | Use the strict equality operator in the `if` statement so the function will return "Equal" when `val` is strictly equal to `7` 19 | -------------------------------------------------------------------------------- /Basic JavaScript/059 practice comparing different values/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | function compareEquality(a, b) { 3 | if (a === b) { // Change this line 4 | return "Equal"; 5 | } 6 | return "Not Equal"; 7 | } 8 | 9 | // Change this value to test 10 | compareEquality(10, "10"); -------------------------------------------------------------------------------- /Basic JavaScript/060 comparison with the inequality operator/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | function testNotEqual(val) { 3 | if (val != 99) { // Change this line 4 | return "Not Equal"; 5 | } 6 | return "Equal"; 7 | } 8 | 9 | // Change this value to test 10 | testNotEqual(10); -------------------------------------------------------------------------------- /Basic JavaScript/060 comparison with the inequality operator/inequality.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The inequality operator (`!=`) is the opposite of the equality operator. It means `"Not Equal"` and returns `false` where equality would return true and vice versa. :star: Like the equality operator, the inequality operator will convert data types of values while comparing. 4 | 5 | Examples 6 | 7 | ```javascript 8 | 1 != 2; // true 9 | 1 != "1"; // false 10 | 1 != "1"; // false 11 | 1 != true; // false 12 | 0 != false; // false 13 | ``` 14 | 15 | :fire: 16 | 17 | Add the inequality operator `!=` in the `if` statement so that the function will return `"Not Equal"` when `val` is not equivalent to `99`. 18 | -------------------------------------------------------------------------------- /Basic JavaScript/061 comparison with strict inequality operator/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | function testStrictNotEqual(val) { 3 | // Only Change Code Below this Line 4 | 5 | if (val !== 17) { 6 | 7 | // Only Change Code Above this Line 8 | 9 | return "Not Equal"; 10 | } 11 | return "Equal"; 12 | } 13 | 14 | // Change this value to test 15 | testStrictNotEqual(10); -------------------------------------------------------------------------------- /Basic JavaScript/061 comparison with strict inequality operator/strictinequality.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The strict inequality operator (`!==`) is the logical opposite of the strict equality operator. It means "Strictly Not Equal" and returns `false` where strict equality would return true and vice versa. :start: Strict inequality will not convert data types. 4 | 5 | Examples 6 | 7 | ```javascript 8 | 3 !== 3; // false 9 | 3 !== "3"; // true 10 | 4 !== 3; // true 11 | ``` 12 | 13 | :fire: 14 | 15 | Add the _strict inequality operator_ to the `if` statement so the function will return `"Not Equal"` when `val` is not strictly equal to `17` 16 | -------------------------------------------------------------------------------- /Basic JavaScript/062 comparison with the greater than operator/greaterthanoperator.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The greater than operator (`>`) compares the values of two numbers. If the number to the left is greater than the number to the right, it returns `true`. Otherwise, it returns `false`. 4 | 5 | :star: Like the equality operator, greater than operator will convert data types of values while comparing. 6 | 7 | Examples 8 | 9 | ```javascript 10 | 5 > 3; // true 11 | 7 > "3"; // true 12 | 2 > 3; // false 13 | "1" > 9; // false 14 | ``` 15 | 16 | :fire: 17 | 18 | Add the `greater than` operator to the indicated lines so that the return statements make sense. 19 | -------------------------------------------------------------------------------- /Basic JavaScript/062 comparison with the greater than operator/index.js: -------------------------------------------------------------------------------- 1 | function testGreaterThan(val) { 2 | if (val > 100 ) { // Change this line 3 | return "Over 100"; 4 | } 5 | 6 | if (val > 10 ) { // Change this line 7 | return "Over 10"; 8 | } 9 | 10 | return "10 or Under"; 11 | } 12 | 13 | // Change this value to test 14 | testGreaterThan(10); -------------------------------------------------------------------------------- /Basic JavaScript/063 comparison with the greter then or equal/greaterthanequal.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The greater than or equal to operator (`>=`) compares the values of two numbers. If the number to the left is greater than or equal to the number to the right, it returns `true`. Otherwise, it returns `false`. 4 | 5 | Like the equality operator, `greater than or equal to` operator will convert data types while comparing. 6 | 7 | Examples 8 | 9 | ```javascript 10 | 6 >= 6; // true 11 | 7 >= "3"; // true 12 | 2 >= 3; // false 13 | "7" >= 9; // false 14 | ``` 15 | 16 | :fire: 17 | 18 | Add the `greater than or equal to` operator to the indicated lines so that the return statements make sense. 19 | -------------------------------------------------------------------------------- /Basic JavaScript/063 comparison with the greter then or equal/index.js: -------------------------------------------------------------------------------- 1 | function testGreaterOrEqual(val) { 2 | if (val >= 20) { 3 | // Change this line 4 | return "20 or Over"; 5 | } 6 | 7 | if (val >= 10) { 8 | // Change this line 9 | return "10 or Over"; 10 | } 11 | 12 | return "Less than 10"; 13 | } 14 | 15 | // Change this value to test 16 | testGreaterOrEqual(10); 17 | -------------------------------------------------------------------------------- /Basic JavaScript/064 comparison with the less than operator/index.js: -------------------------------------------------------------------------------- 1 | function testLessThan(val) { 2 | if (val < 25) { // Change this line 3 | return "Under 25"; 4 | } 5 | 6 | if (val < 55) { // Change this line 7 | return "Under 55"; 8 | } 9 | 10 | return "55 or Over"; 11 | } 12 | 13 | // Change this value to test 14 | testLessThan(10); -------------------------------------------------------------------------------- /Basic JavaScript/064 comparison with the less than operator/lessthan.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The less than operator (`<`) compares the values of two numbers. If the number to the left is less than the number to the right, it returns `true`. Otherwise, it returns `false`. Like the equality operator, less than operator converts data types while comparing. 4 | 5 | Examples 6 | 7 | ```javascript 8 | 2 < 5; // true 9 | "3" < 7; // true 10 | 5 < 5; // false 11 | 3 < 2; // false 12 | "8" < 4; // false 13 | ``` 14 | 15 | :fire: 16 | 17 | Add the `less than operator` to the indicated lines so that the return statements make sense. 18 | -------------------------------------------------------------------------------- /Basic JavaScript/065 comparison with less than or equal to operator/index.js: -------------------------------------------------------------------------------- 1 | function testLessOrEqual(val) { 2 | if (val <= 12) { // Change this line 3 | return "Smaller Than or Equal to 12"; 4 | } 5 | 6 | if (val <= 24 ) { // Change this line 7 | return "Smaller Than or Equal to 24"; 8 | } 9 | 10 | return "More Than 24"; 11 | } 12 | 13 | // Change this value to test 14 | testLessOrEqual(10); 15 | -------------------------------------------------------------------------------- /Basic JavaScript/065 comparison with less than or equal to operator/lessthanorequal.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The less than or equal to operator (`<=`) compares the values of two numbers. If the number to the left is less than or equal to the number to the right, it returns `true`. If the number on the left is greater than the number on the right, it returns `false`. Like the equality operator, less than or equal to converts data types. 4 | 5 | Examples 6 | 7 | ```javascript 8 | 4 <= 5; // true 9 | "7" <= 7; // true 10 | 5 <= 5; // true 11 | 3 <= 2; // false 12 | "8" <= 4; // false 13 | ``` 14 | 15 | :fire: 16 | 17 | Add the `less than or equal to` operator to the indicated lines so that the return statements make sense. 18 | -------------------------------------------------------------------------------- /Basic JavaScript/066 comparison with the logical and operator/index.js: -------------------------------------------------------------------------------- 1 | function testLogicalAnd(val) { 2 | // Only change code below this line 3 | 4 | if (val <= 50 && val >= 25) { 5 | return "Yes"; 6 | } 7 | 8 | // Only change code above this line 9 | return "No"; 10 | } 11 | 12 | // Change this value to test 13 | testLogicalAnd(10); -------------------------------------------------------------------------------- /Basic JavaScript/067 comparison with logical or operator/index.js: -------------------------------------------------------------------------------- 1 | function testLogicalOr(val) { 2 | // Only change code below this line 3 | 4 | if (val < 10 || val > 20) { 5 | return "Outside"; 6 | } 7 | 8 | // Only change code above this line 9 | return "Inside"; 10 | } 11 | 12 | // Change this value to test 13 | console.log(testLogicalOr(20)) -------------------------------------------------------------------------------- /Basic JavaScript/068 introducing else statements/elsestatement.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | When a condition for an `if` statement is true, the block of code following it is executed. What about when that condition is false? Normally nothing would happen. With an else statement, an alternate block of code can be executed. 4 | 5 | ```javascript 6 | if (num > 10) { 7 | return "Bigger than 10"; 8 | } else { 9 | return "10 or Less"; 10 | } 11 | ``` 12 | 13 | :fire: 14 | 15 | Combine the `if` statements into a single `if/else` statement. 16 | -------------------------------------------------------------------------------- /Basic JavaScript/068 introducing else statements/index.js: -------------------------------------------------------------------------------- 1 | function testElse(val) { 2 | var result = ""; 3 | // Only change code below this line 4 | 5 | if (val > 5) { 6 | result = "Bigger than 5"; 7 | } 8 | 9 | else { 10 | result = "5 or Smaller"; 11 | } 12 | 13 | // Only change code above this line 14 | return result; 15 | } 16 | 17 | // Change this value to test 18 | testElse(4); 19 | -------------------------------------------------------------------------------- /Basic JavaScript/069 introducing else if statements/elseifstatements.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | If you have multiple conditions that need to be addressed, you can chain `if` statements together with `else if` statements. 4 | 5 | ```javascript 6 | if (num > 15) { 7 | return "Bigger than 15"; 8 | } else if (num < 5) { 9 | return "Smaller than 5"; 10 | } else { 11 | return "Between 5 and 15"; 12 | } 13 | ``` 14 | 15 | :fire: 16 | 17 | Convert the logic to use else if statements. 18 | -------------------------------------------------------------------------------- /Basic JavaScript/069 introducing else if statements/index.js: -------------------------------------------------------------------------------- 1 | function testElseIf(val) { 2 | if (val > 10) { 3 | return "Greater than 10"; 4 | } else if (val < 5) { 5 | return "Smaller than 5"; 6 | } else { 7 | return "Between 5 and 10"; 8 | } 9 | } 10 | 11 | // Change this value to test 12 | testElseIf(7); 13 | -------------------------------------------------------------------------------- /Basic JavaScript/070 logical order in if else statements/index.js: -------------------------------------------------------------------------------- 1 | function orderMyLogic(val) { 2 | if (val < 5) { 3 | return "Less than 5"; 4 | } else if (val < 10) { 5 | return "Less than 10"; 6 | } else { 7 | return "Greater than or equal to 10"; 8 | } 9 | } 10 | 11 | // Change this value to test 12 | orderMyLogic(7); -------------------------------------------------------------------------------- /Basic JavaScript/071 chaining if else statements/chainifelse.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | `if/else` statements can be chained together for complex logic. Here is _pseudo code_ of multiple chained `if / else` if statements: 4 | 5 | ```javascript 6 | if (condition1) { 7 | statement1 8 | } else if (condition2) { 9 | statement2 10 | } else if (condition3) { 11 | statement3 12 | . . . 13 | } else { 14 | statementN 15 | } 16 | ``` 17 | 18 | :fire: 19 | 20 | Write chained `if/else` if statements to fulfill the following conditions: 21 | 22 | `num < 5` - return "Tiny" 23 | `num < 10` - return "Small" 24 | `num < 15` - return "Medium" 25 | `num < 20` - return "Large" 26 | `num >= 20` - return "Huge" 27 | -------------------------------------------------------------------------------- /Basic JavaScript/071 chaining if else statements/index.js: -------------------------------------------------------------------------------- 1 | function testSize(num) { 2 | // Only change code below this line 3 | if (num < 5) return "Tiny"; 4 | else if (num < 10) return "Small"; 5 | else if (num < 15) return "Medium"; 6 | else if (num < 20) return "Large"; 7 | else return "Huge"; 8 | 9 | return "Change Me"; 10 | // Only change code above this line 11 | } 12 | 13 | // Change this value to test 14 | testSize(7); 15 | -------------------------------------------------------------------------------- /Basic JavaScript/072 golf code/index.js: -------------------------------------------------------------------------------- 1 | var names = [ 2 | "Hole-in-one!", 3 | "Eagle", 4 | "Birdie", 5 | "Par", 6 | "Bogey", 7 | "Double Bogey", 8 | "Go Home!" 9 | ]; 10 | function golfScore(par, strokes) { 11 | // Only change code below this line 12 | if (strokes === 1) return names[0]; 13 | else if (strokes <= par - 2) return names[1]; 14 | else if (strokes === par - 1) return names[2]; 15 | else if (strokes === par) return names[3]; 16 | else if (strokes === par + 1) return names[4]; 17 | else if (strokes === par + 2) return names[5]; 18 | else if (strokes >= par + 3) return names[6]; 19 | else return "Change Me"; 20 | // Only change code above this line 21 | } 22 | 23 | // Change these values to test 24 | golfScore(5, 4); 25 | -------------------------------------------------------------------------------- /Basic JavaScript/073 selecting from many options with switch statements/index.js: -------------------------------------------------------------------------------- 1 | function caseInSwitch(val) { 2 | var answer = ""; 3 | // Only change code below this line 4 | 5 | switch (val) { 6 | case 1: 7 | answer = "alpha"; 8 | break; 9 | case 2: 10 | answer = "beta"; 11 | break; 12 | case 3: 13 | answer = "gamma"; 14 | break; 15 | case 4: 16 | answer = "delta"; 17 | break; 18 | } 19 | 20 | // Only change code above this line 21 | return answer; 22 | } 23 | 24 | // Change this value to test 25 | caseInSwitch(1); 26 | -------------------------------------------------------------------------------- /Basic JavaScript/074 adding default options in switch statements/index.js: -------------------------------------------------------------------------------- 1 | function switchOfStuff(val) { 2 | var answer = ""; 3 | // Only change code below this line 4 | switch (val) { 5 | case "a": 6 | answer = "apple"; 7 | break; 8 | case "b": 9 | answer = "bird"; 10 | break; 11 | case "c": 12 | answer = "cat"; 13 | break; 14 | default: 15 | answer = "stuff"; 16 | } 17 | 18 | // Only change code above this line 19 | return answer; 20 | } 21 | 22 | // Change this value to test 23 | switchOfStuff(1); 24 | -------------------------------------------------------------------------------- /Basic JavaScript/075 multiple identical options in switch statements/index.js: -------------------------------------------------------------------------------- 1 | function sequentialSizes(val) { 2 | var answer = ""; 3 | // Only change code below this line 4 | 5 | switch (val) { 6 | case 1: 7 | case 2: 8 | case 3: 9 | answer = "Low"; 10 | break; 11 | case 4: 12 | case 5: 13 | case 6: 14 | answer = "Mid"; 15 | break; 16 | case 7: 17 | case 8: 18 | case 9: 19 | answer = "High"; 20 | break; 21 | } 22 | 23 | // Only change code above this line 24 | return answer; 25 | } 26 | 27 | // Change this value to test 28 | sequentialSizes(1); 29 | -------------------------------------------------------------------------------- /Basic JavaScript/076 replacing if else chains with switch/index.js: -------------------------------------------------------------------------------- 1 | function chainToSwitch(val) { 2 | var answer = ""; 3 | // Only change code below this line 4 | 5 | switch (val) { 6 | case "bob": 7 | answer = "Marley"; 8 | break; 9 | case 42: 10 | answer = "The Answer"; 11 | break; 12 | case 1: 13 | answer = "There is no #1"; 14 | break; 15 | case 99: 16 | answer = "Missed me by this much!"; 17 | break; 18 | case 7: 19 | answer = "Ate Nine"; 20 | break; 21 | default: 22 | return answer; 23 | } 24 | 25 | // Only change code above this line 26 | return answer; 27 | } 28 | 29 | // Change this value to test 30 | chainToSwitch(7); 31 | -------------------------------------------------------------------------------- /Basic JavaScript/076 replacing if else chains with switch/replaceifelse.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | If you have many options to choose from, a `switch` statement can be easier to write than many chained `if/else if` statements. The following: 4 | 5 | ```javascript 6 | if (val === 1) { 7 | answer = "a"; 8 | } else if (val === 2) { 9 | answer = "b"; 10 | } else { 11 | answer = "c"; 12 | } 13 | ``` 14 | 15 | can be replaced with: 16 | 17 | ```javascript 18 | switch (val) { 19 | case 1: 20 | answer = "a"; 21 | break; 22 | case 2: 23 | answer = "b"; 24 | break; 25 | default: 26 | answer = "c"; 27 | } 28 | ``` 29 | 30 | :fire: 31 | 32 | Change the chained `if/else if` statements into a `switch` statement. 33 | -------------------------------------------------------------------------------- /Basic JavaScript/077 returing boolean values from functions/index.js: -------------------------------------------------------------------------------- 1 | function isLess(a, b) { 2 | // Fix this code 3 | return a < b; 4 | } 5 | 6 | // Change these values to test 7 | isLess(10, 15); 8 | -------------------------------------------------------------------------------- /Basic JavaScript/077 returing boolean values from functions/returnboolean.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | You may recall from `Comparison with the Equality Operator` that all comparison operators return a boolean `true` or `false` value. 4 | 5 | Sometimes people use an if/else statement to do a comparison, like this: 6 | 7 | ```javascript 8 | function isEqual(a, b) { 9 | if (a === b) { 10 | return true; 11 | } else { 12 | return false; 13 | } 14 | } 15 | ``` 16 | 17 | But there's a better way to do this. Since `===` returns `true` or fa`lse, we can return the result of the comparison: 18 | 19 | ```javascript 20 | function isEqual(a, b) { 21 | return a === b; 22 | } 23 | ``` 24 | 25 | :fire: 26 | 27 | Fix the function `isLess` to remove the `if/else` statements. 28 | -------------------------------------------------------------------------------- /Basic JavaScript/078 return early patterns for functions/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | function abTest(a, b) { 3 | // Only change code below this line 4 | if (a < 0 || b < 0) return undefined; 5 | 6 | // Only change code above this line 7 | 8 | return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2)); 9 | } 10 | 11 | // Change values below to test your code 12 | abTest(2, 2); 13 | -------------------------------------------------------------------------------- /Basic JavaScript/078 return early patterns for functions/returnpattern.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | When a `return` statement is reached, the execution of the current function stops and control returns to the calling location. 4 | 5 | Example 6 | 7 | ```javascript 8 | function myFun() { 9 | console.log("Hello"); 10 | return "World"; 11 | console.log("byebye"); 12 | } 13 | myFun(); 14 | ``` 15 | 16 | The above outputs "Hello" to the console, returns "World", but "byebye" is never output, because the function exits at the return statement. 17 | 18 | :fire: 19 | 20 | Modify the function `abTest` so that if `a` or `b` are less than `0` the function will immediately exit with a value of `undefined`. 21 | 22 | Hint 23 | 24 | :zap: Remember that `undefined` is a keyword, not a string. 25 | -------------------------------------------------------------------------------- /Basic JavaScript/080 build javascript objects/counting-card.js: -------------------------------------------------------------------------------- 1 | let count = 0; 2 | 3 | function cc(card) { 4 | // Only change code below this line 5 | switch (card) { 6 | case 2: 7 | case 3: 8 | case 4: 9 | case 5: 10 | case 6: 11 | count++; 12 | break; 13 | case 10: 14 | case "J": 15 | case "Q": 16 | case "K": 17 | case "A": 18 | count--; 19 | break; 20 | } 21 | if (count > 0) { 22 | return count + " Bet"; 23 | } else { 24 | return count + " Hold"; 25 | } 26 | // Only change code above this line 27 | } 28 | 29 | cc(2); cc(3); cc(7); cc('K'); cc('A'); 30 | -------------------------------------------------------------------------------- /Basic JavaScript/080 build javascript objects/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourDog = { 3 | "name": "Camper", 4 | "legs": 4, 5 | "tails": 1, 6 | "friends": ["everything!"] 7 | }; 8 | 9 | // Only change code below this line. 10 | 11 | var myDog = { 12 | "name": "Jordan", 13 | "legs": 4, 14 | "tails": 1, 15 | "friends": ["John", "Sam"] 16 | 17 | }; -------------------------------------------------------------------------------- /Basic JavaScript/081 accessing object properties with dot notation/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | var testObj = { 3 | "hat": "ballcap", 4 | "shirt": "jersey", 5 | "shoes": "cleats" 6 | }; 7 | 8 | // Only change code below this line 9 | 10 | var hatValue = testObj.hat; // Change this line 11 | var shirtValue = testObj.shirt; // Change this line -------------------------------------------------------------------------------- /Basic JavaScript/082 accessing object properties with bracket notaion/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | var testObj = { 3 | "an entree": "hamburger", 4 | "my side": "veggies", 5 | "the drink": "water" 6 | }; 7 | 8 | // Only change code below this line 9 | 10 | var entreeValue = testObj["an entree"]; // Change this line 11 | var drinkValue = testObj["the drink"]; // Change this line -------------------------------------------------------------------------------- /Basic JavaScript/083 accessing object properties with variables/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | var testObj = { 3 | 12: "Namath", 4 | 16: "Montana", 5 | 19: "Unitas" 6 | }; 7 | 8 | // Only change code below this line; 9 | 10 | var playerNumber = 16; // Change this Line 11 | var player = testObj[playerNumber]; // Change this Line -------------------------------------------------------------------------------- /Basic JavaScript/084 updating object properties/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourDog = { 3 | name: "Camper", 4 | legs: 4, 5 | tails: 1, 6 | friends: ["everything!"] 7 | }; 8 | 9 | ourDog.name = "Happy Camper"; 10 | 11 | // Setup 12 | var myDog = { 13 | name: "Coder", 14 | legs: 4, 15 | tails: 1, 16 | friends: ["freeCodeCamp Campers"] 17 | }; 18 | 19 | // Only change code below this line. 20 | myDog.name = "Happy Coder"; 21 | -------------------------------------------------------------------------------- /Basic JavaScript/085 add new properties to a Js object/addnewproperty.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | You can add new properties to existing JavaScript objects the same way you would modify them. 4 | 5 | Here's how we would add a `"bark"` property to `ourDog`: 6 | 7 | ```javascript 8 | ourDog.bark = "bow-wow"; 9 | ``` 10 | 11 | or 12 | 13 | ```javascript 14 | ourDog["bark"] = "bow-wow"; 15 | ``` 16 | 17 | Now when we evaluate `ourDog.bark`, we'll get his bark, "bow-wow". 18 | 19 | :fire: 20 | 21 | Add a `"bark"` property to `myDog` and set it to a dog sound, such as "woof". You may use either dot or bracket notation. 22 | -------------------------------------------------------------------------------- /Basic JavaScript/085 add new properties to a Js object/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourDog = { 3 | "name": "Camper", 4 | "legs": 4, 5 | "tails": 1, 6 | "friends": ["everything!"] 7 | }; 8 | 9 | ourDog.bark = "bow-wow"; 10 | 11 | // Setup 12 | var myDog = { 13 | "name": "Happy Coder", 14 | "legs": 4, 15 | "tails": 1, 16 | "friends": ["freeCodeCamp Campers"] 17 | }; 18 | 19 | // Only change code below this line. 20 | myDog["bark"] = "woof"; -------------------------------------------------------------------------------- /Basic JavaScript/086 delete properties from Js object/deleteproperties.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | We can also delete properties from objects like this: 4 | 5 | ```javascript 6 | delete ourDog.bark; 7 | ``` 8 | 9 | :fire: 10 | 11 | Delete the `"tails"` property from `myDog`. You may use either dot or bracket notation. 12 | -------------------------------------------------------------------------------- /Basic JavaScript/086 delete properties from Js object/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourDog = { 3 | name: "Camper", 4 | legs: 4, 5 | tails: 1, 6 | friends: ["everything!"], 7 | bark: "bow-wow" 8 | }; 9 | 10 | delete ourDog.bark; 11 | 12 | // Setup 13 | var myDog = { 14 | name: "Happy Coder", 15 | legs: 4, 16 | tails: 1, 17 | friends: ["freeCodeCamp Campers"], 18 | bark: "woof" 19 | }; 20 | 21 | // Only change code below this line. 22 | delete myDog.tails; 23 | -------------------------------------------------------------------------------- /Basic JavaScript/087 using objects for lookups/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | function phoneticLookup(val) { 3 | var result = ""; 4 | 5 | // Only change code below this line 6 | var lookup = { 7 | alpha: "Adams", 8 | bravo: "Boston", 9 | charlie: "Chicago", 10 | delta: "Denver", 11 | echo: "Easy", 12 | foxtrot: "Frank" 13 | }; 14 | 15 | result = lookup[val]; 16 | // Only change code above this line 17 | return result; 18 | } 19 | 20 | // Change this value to test 21 | phoneticLookup("charlie"); 22 | -------------------------------------------------------------------------------- /Basic JavaScript/088 testing objects for properties/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | var myObj = { 3 | gift: "pony", 4 | pet: "kitten", 5 | bed: "sleigh" 6 | }; 7 | 8 | function checkObj(checkProp) { 9 | // Your Code Here 10 | if (myObj.hasOwnProperty(checkProp) === true) { 11 | return myObj[checkProp]; 12 | } else { 13 | return "Not Found"; 14 | } 15 | } 16 | 17 | // Test your code by modifying these values 18 | console.log(checkObj("gift")); 19 | 20 | -------------------------------------------------------------------------------- /Basic JavaScript/088 testing objects for properties/objectforproperties.md: -------------------------------------------------------------------------------- 1 | :coffee: :star: 2 | 3 | Sometimes it is useful to check if the property of a given object exists or not. We can use the `.hasOwnProperty(propname)` method of objects to determine if that object has the given property name. :zap: `.hasOwnProperty()` returns true or false if the property is found or not. 4 | 5 | Example 6 | 7 | ```javascript 8 | var myObj = { 9 | top: "hat", 10 | bottom: "pants" 11 | }; 12 | myObj.hasOwnProperty("top"); // true 13 | myObj.hasOwnProperty("middle"); // false 14 | ``` 15 | 16 | :fire: 17 | 18 | Modify the function `checkObj` to test `myObj` for `checkProp`. If the property is found, return that property's value. If not, return `"Not Found"`. 19 | -------------------------------------------------------------------------------- /Basic JavaScript/089 manipulating complex objects/index.js: -------------------------------------------------------------------------------- 1 | var myMusic = [ 2 | { 3 | "artist": "Billy Joel", 4 | "title": "Piano Man", 5 | "release_year": 1973, 6 | "formats": [ 7 | "CD", 8 | "8T", 9 | "LP" 10 | ], 11 | "gold": true 12 | }, 13 | // Add record here 14 | { 15 | "artist": "Eminem", 16 | "title": "Recovery", 17 | "release_year": 2014, 18 | "formats": ["Spotify", "iTunes", "Savan"] 19 | } 20 | ]; 21 | -------------------------------------------------------------------------------- /Basic JavaScript/090 accessing nested objects/accessnestesobject.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The sub-properties of objects can be accessed by chaining together the dot or bracket notation. 4 | 5 | Here is a nested object: 6 | 7 | ```javascript 8 | var ourStorage = { 9 | desk: { 10 | drawer: "stapler" 11 | }, 12 | cabinet: { 13 | "top drawer": { 14 | folder1: "a file", 15 | folder2: "secrets" 16 | }, 17 | "bottom drawer": "soda" 18 | } 19 | }; 20 | ourStorage.cabinet["top drawer"].folder2; // "secrets" 21 | ourStorage.desk.drawer; // "stapler" 22 | ``` 23 | 24 | :fire: 25 | 26 | Access the `myStorage` object and assign the contents of the `glove box` property to the `gloveBoxContents` variable. Use bracket notation for properties with a space in their name. 27 | -------------------------------------------------------------------------------- /Basic JavaScript/090 accessing nested objects/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | var myStorage = { 3 | car: { 4 | inside: { 5 | "glove box": "maps", 6 | "passenger seat": "crumbs" 7 | }, 8 | outside: { 9 | trunk: "jack" 10 | } 11 | } 12 | }; 13 | 14 | var gloveBoxContents = myStorage.car.inside["glove box"]; // Change this line 15 | -------------------------------------------------------------------------------- /Basic JavaScript/091 accessing nested arrays/accessnestedarays.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | As we have seen in earlier examples, objects can contain both nested objects and nested arrays. Similar to accessing nested objects, Array bracket notation can be chained to access nested arrays. 4 | 5 | Here is an example of how to access a nested array: 6 | 7 | ```javascript 8 | var ourPets = [ 9 | { 10 | animalType: "cat", 11 | names: ["Meowzer", "Fluffy", "Kit-Cat"] 12 | }, 13 | { 14 | animalType: "dog", 15 | names: ["Spot", "Bowser", "Frankie"] 16 | } 17 | ]; 18 | ourPets[0].names[1]; // "Fluffy" 19 | ourPets[1].names[0]; // "Spot" 20 | ``` 21 | 22 | :fire: 23 | 24 | Retrieve the second tree from the variable `myPlants` using object dot and array bracket notation. 25 | -------------------------------------------------------------------------------- /Basic JavaScript/091 accessing nested arrays/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | var myPlants = [ 3 | { 4 | type: "flowers", 5 | list: [ 6 | "rose", 7 | "tulip", 8 | "dandelion" 9 | ] 10 | }, 11 | { 12 | type: "trees", 13 | list: [ 14 | "fir", 15 | "pine", 16 | "birch" 17 | ] 18 | } 19 | ]; 20 | 21 | // Only change code below this line 22 | 23 | var secondTree = myPlants[1].list[1]; // Change this line 24 | -------------------------------------------------------------------------------- /Basic JavaScript/092 record collection/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnasamx/freecodecamp/e5d9f29c156baab5a441448c5b30ccae2eeae015/Basic JavaScript/092 record collection/index.js -------------------------------------------------------------------------------- /Basic JavaScript/093 iterate with Js while loops/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | var myArray = []; 3 | 4 | // Only change code below this line. 5 | 6 | var i = 0; 7 | while (i < 5) { 8 | myArray.push(i); 9 | i++; 10 | } 11 | -------------------------------------------------------------------------------- /Basic JavaScript/093 iterate with Js while loops/while.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | You can run the same code multiple times by using a loop. 4 | 5 | The first type of loop we will learn is called a `"while"` loop because it runs "while" a specified condition is true and stops once that condition is no longer true. 6 | 7 | ```javascript 8 | var ourArray = []; 9 | var i = 0; 10 | while (i < 5) { 11 | ourArray.push(i); 12 | i++; 13 | } 14 | ``` 15 | 16 | Let's try getting a while loop to work by pushing values to an array. 17 | 18 | :fire: 19 | 20 | Push the numbers 0 through 4 to `myArray` using a `while` loop. 21 | -------------------------------------------------------------------------------- /Basic JavaScript/094 iterate with Js for loops/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourArray = []; 3 | 4 | for (var i = 0; i < 5; i++) { 5 | ourArray.push(i); 6 | } 7 | 8 | // Setup 9 | var myArray = []; 10 | 11 | // Only change code below this line. 12 | 13 | for (var i = 1; i <= 5; i++) { 14 | myArray.push(i); 15 | } 16 | -------------------------------------------------------------------------------- /Basic JavaScript/095 iterate odd number with for loop/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourArray = []; 3 | 4 | for (var i = 0; i < 10; i += 2) { 5 | ourArray.push(i); 6 | } 7 | 8 | // Setup 9 | var myArray = []; 10 | 11 | // Only change code below this line. 12 | 13 | for (var i = 1; i < 10; i += 2) { 14 | myArray.push(i); 15 | } 16 | -------------------------------------------------------------------------------- /Basic JavaScript/095 iterate odd number with for loop/iterateforodd.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | For loops don't have to iterate one at a time. By changing our `final-expression`, we can count by even numbers. 4 | 5 | We'll start at `i = 0` and loop while `i < 10`. We'll increment `i` by 2 each loop with `i += 2`. 6 | 7 | ```javascript 8 | var ourArray = []; 9 | for (var i = 0; i < 10; i += 2) { 10 | ourArray.push(i); 11 | } 12 | ``` 13 | 14 | `ourArray` will now contain `[0,2,4,6,8]`. 15 | 16 | Let's change our `initialization` so we can count by odd numbers. 17 | 18 | :fire: 19 | 20 | Push the odd numbers from 1 through 9 to `myArray` using a `for` loop. 21 | -------------------------------------------------------------------------------- /Basic JavaScript/096 count backwards with a for loop/countbackwards.md: -------------------------------------------------------------------------------- 1 | :fire: 2 | 3 | A for loop can also count backwards, so long as we can define the right conditions. 4 | 5 | In order to count backwards by twos, we'll need to change our `initialization`, `condition`, and `final-expression`. 6 | 7 | We'll start at `i = 10` and loop while `i > 0`. We'll decrement `i` by 2 each loop with `i -= 2`. 8 | 9 | ```javascript 10 | var ourArray = []; 11 | for (var i = 10; i > 0; i -= 2) { 12 | ourArray.push(i); 13 | } 14 | ``` 15 | 16 | `ourArray` will now contain `[10,8,6,4,2]`. 17 | 18 | Let's change our `initialization` and `final-expression` so we can count backward by twos by odd numbers. 19 | 20 | :fire: 21 | 22 | Push the odd numbers from 9 through 1 to `myArray` using a `for` loop. 23 | -------------------------------------------------------------------------------- /Basic JavaScript/096 count backwards with a for loop/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourArray = []; 3 | 4 | for (var i = 10; i > 0; i -= 2) { 5 | ourArray.push(i); 6 | } 7 | 8 | // Setup 9 | var myArray = []; 10 | 11 | // Only change code below this line. 12 | 13 | for (var i = 9; i > 0; i -= 2) { 14 | myArray.push(i); 15 | } 16 | -------------------------------------------------------------------------------- /Basic JavaScript/097 iterate through an array with a for loop/arrayforloop.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | A common task in JavaScript is to iterate through the contents of an array. One way to do that is with a `for` loop. This code will output each element of the array arr to the console: 4 | 5 | var arr = [10,9,8,7,6]; 6 | for (var i = 0; i < arr.length; i++) { 7 | console.log(arr[i]); 8 | } 9 | Remember that Arrays have zero-based numbering, which means the last index of the array is length - 1. Our condition for this loop is i < arr.length, which stops when i is at length - 1. 10 | 11 | :fire: 12 | 13 | Declare and initialize a variable `total` to `0`. Use a for loop to add the value of each element of the `myArr` array to `total`. 14 | -------------------------------------------------------------------------------- /Basic JavaScript/097 iterate through an array with a for loop/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | var ourArr = [9, 10, 11, 12]; 3 | var ourTotal = 0; 4 | var total = 0; 5 | 6 | for (var i = 0; i < ourArr.length; i++) { 7 | ourTotal += ourArr[i]; 8 | } 9 | 10 | // Setup 11 | var myArr = [2, 3, 4, 5, 6]; 12 | 13 | // Only change code below this line 14 | 15 | for (i = 0; i < myArr.length; i++) { 16 | total += myArr[i]; 17 | } 18 | -------------------------------------------------------------------------------- /Basic JavaScript/098 nesting loops/index.js: -------------------------------------------------------------------------------- 1 | function multiplyAll(arr) { 2 | var product = 1; 3 | // Only change code below this line 4 | for (var i = 0; i < arr.length; i++) { 5 | for (var j = 0; j < arr[i].length; j++) { 6 | product *= arr[i][j]; 7 | } 8 | } 9 | // Only change code above this line 10 | return product; 11 | } 12 | 13 | // Modify values below to test your code 14 | multiplyAll([[1, 2], [3, 4], [5, 6, 7]]); 15 | -------------------------------------------------------------------------------- /Basic JavaScript/098 nesting loops/nestingloops.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | If you have a multi-dimensional array, you can use the same logic as the prior waypoint to loop through both the array and any sub-arrays. Here is an example: 4 | 5 | ```javascript 6 | var arr = [[1, 2], [3, 4], [5, 6]]; 7 | for (var i = 0; i < arr.length; i++) { 8 | for (var j = 0; j < arr[i].length; j++) { 9 | console.log(arr[i][j]); 10 | } 11 | } 12 | ``` 13 | 14 | This outputs each sub-element in `arr` one at a time. Note that for the inner loop, we are checking the `.length` of `arr[i]`, since `arr[i]` is itself an array. 15 | 16 | :fire: 17 | 18 | Modify function `multiplyAll` so that it multiplies the `product` variable by each number in the sub-arrays of `arr` 19 | -------------------------------------------------------------------------------- /Basic JavaScript/099 iterate with Js do while loop/index.js: -------------------------------------------------------------------------------- 1 | // Setup 2 | var myArray = []; 3 | var i = 10; 4 | 5 | // Only change code below this line. 6 | 7 | do { 8 | myArray.push(i); 9 | i++; 10 | } while (i < 5); 11 | -------------------------------------------------------------------------------- /Basic JavaScript/100 perfect lookup/perfectloopup.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | We have an array of objects representing different people in our contacts lists. 4 | 5 | A `lookUpProfile` function that takes `name` and a property (`prop`) as arguments has been pre-written for you. 6 | 7 | The function should check if `name` is an actual contact's `firstName` and the given property (`prop`) is a property of that contact. 8 | 9 | If both are true, then return the "value" of that property. 10 | 11 | If `name` does not correspond to any contacts then return `"No such contact"` 12 | 13 | If `prop` does not correspond to any valid properties of a contact found to match `name` then return `"No such property"` 14 | -------------------------------------------------------------------------------- /Basic JavaScript/101 generate random fractions with Js/generatefraction.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Random numbers are useful for creating random behavior. 4 | 5 | JavaScript has a `Math.random()` function that generates a random decimal number between `0` (inclusive) and not quite up to `1` (exclusive). Thus Math.random() can return a 0 but never quite return a 1 6 | 7 | Note 8 | Like Storing Values with the Equal Operator, all function calls will be resolved before the return executes, so we can return the value of the Math.random() function. 9 | 10 | :fire: 11 | 12 | Change `randomFraction` to return a random number instead of returning `0`. 13 | -------------------------------------------------------------------------------- /Basic JavaScript/101 generate random fractions with Js/index.js: -------------------------------------------------------------------------------- 1 | function randomFraction() { 2 | 3 | // Only change code below this line. 4 | 5 | return Math.random(); 6 | 7 | // Only change code above this line. 8 | } -------------------------------------------------------------------------------- /Basic JavaScript/102 generate random whole number with Js/index.js: -------------------------------------------------------------------------------- 1 | var randomNumberBetween0and19 = Math.floor(Math.random() * 20); 2 | 3 | function randomWholeNum() { 4 | // Only change code below this line. 5 | 6 | return Math.floor(Math.random() * 10); 7 | } 8 | -------------------------------------------------------------------------------- /Basic JavaScript/103 generate randome whole numbers within a range/index.js: -------------------------------------------------------------------------------- 1 | // Example 2 | function ourRandomRange(ourMin, ourMax) { 3 | return Math.floor(Math.random() * (ourMax - ourMin + 1)) + ourMin; 4 | } 5 | 6 | ourRandomRange(1, 9); 7 | 8 | // Only change code below this line. 9 | 10 | function randomRange(myMin, myMax) { 11 | return Math.floor(Math.random() * (myMax - myMin + 1) + myMin); // Change this line 12 | } 13 | 14 | // Change these values to test your function 15 | var myRandom = randomRange(5, 15); 16 | -------------------------------------------------------------------------------- /Basic JavaScript/103 generate randome whole numbers within a range/wholenumberrange.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Instead of generating a random number between zero and a given number like we did before, we can generate a random number that falls within a range of two specific numbers. 4 | 5 | To do this, we'll define a minimum number `min` and a maximum number max. 6 | 7 | Here's the formula we'll use. Take a moment to read it and try to understand what this code is doing: 8 | 9 | ```javascript 10 | Math.floor(Math.random() * (max - min + 1)) + min; 11 | ``` 12 | 13 | :fire: 14 | 15 | Create a function called randomRange that takes a range myMin and myMax and returns a random number that's greater than or equal to myMin, and is less than or equal to myMax, inclusive. 16 | -------------------------------------------------------------------------------- /Basic JavaScript/104 use the parseint function/index.js: -------------------------------------------------------------------------------- 1 | function convertToInteger(str) { 2 | return parseInt(str); 3 | } 4 | 5 | convertToInteger("56"); 6 | -------------------------------------------------------------------------------- /Basic JavaScript/104 use the parseint function/parseint.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The `parseInt()` function parses a string and returns an integer. Here's an example: 4 | 5 | ```javascript 6 | var a = parseInt("007"); 7 | ``` 8 | 9 | The above function converts the string "007" to an integer 7. If the first character in the string can't be converted into a number, then it returns `NaN`. 10 | 11 | :fire: 12 | 13 | Use `parseInt()` in the `convertToInteger` function so it converts the input string `str` into an integer, and returns it. 14 | -------------------------------------------------------------------------------- /Basic JavaScript/105 use the parseInt function with radix/index.js: -------------------------------------------------------------------------------- 1 | function convertToInteger(str) { 2 | return parseInt(str, 2) 3 | } 4 | 5 | convertToInteger("10011"); -------------------------------------------------------------------------------- /Basic JavaScript/105 use the parseInt function with radix/parseintradix.md: -------------------------------------------------------------------------------- 1 | :coffee: :star2: 2 | 3 | The `parseInt()` function parses a string and returns an integer. :zap: It takes a second argument for the radix, which specifies the base of the number in the string. The radix can be an integer between 2 and 36. 4 | 5 | The function call looks like: 6 | 7 | ```javascript 8 | parseInt(string, radix); 9 | ``` 10 | 11 | And here's an example: 12 | 13 | ```javascript 14 | var a = parse Int("11", 2); 15 | ``` 16 | 17 | The radix variable says that "11" is in the binary system, or base 2. This example converts the string "11" to an integer 3. 18 | 19 | :fire: 20 | 21 | Use `parseInt()` in the convertToInteger function so it converts a binary number to an integer and returns it. 22 | -------------------------------------------------------------------------------- /Basic JavaScript/106 use the conditional(ternary) opertor/index.js: -------------------------------------------------------------------------------- 1 | function checkEqual(a, b) { 2 | return a === b ? true : false; 3 | } 4 | 5 | checkEqual(1, 2); 6 | -------------------------------------------------------------------------------- /Basic JavaScript/107 use multiple conditional operators/index.js: -------------------------------------------------------------------------------- 1 | function checkSign(num) { 2 | return num == 0 ? "zero" : num > 0 ? "positive" : "negative"; 3 | } 4 | 5 | checkSign(10); 6 | -------------------------------------------------------------------------------- /Certificate/FreeCodeCamp Certificaite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnasamx/freecodecamp/e5d9f29c156baab5a441448c5b30ccae2eeae015/Certificate/FreeCodeCamp Certificaite.png -------------------------------------------------------------------------------- /Debugging/01 use the Js console to check the value of a variable/index.js: -------------------------------------------------------------------------------- 1 | let a = 5; 2 | let b = 1; 3 | a++; 4 | // Add your code below this line 5 | console.log(a); 6 | console.log(b); 7 | 8 | let sumAB = a + b; 9 | console.log(sumAB); 10 | -------------------------------------------------------------------------------- /Debugging/02 understanding the diff bw freecodecamp and browser console/index.js: -------------------------------------------------------------------------------- 1 | // Open your browser console 2 | let outputTwo = "This will print to the browser console 2 times"; 3 | // Use console.log() to print the outputTwo variable 4 | console.log(outputTwo); 5 | 6 | let outputOne = "Try to get this to log only once to the browser console"; 7 | // Use console.clear() in the next line to print the outputOne only once 8 | console.clear(); 9 | 10 | // Use console.log() to print the outputOne variable 11 | console.log(outputOne); 12 | -------------------------------------------------------------------------------- /Debugging/03 use typeof to check the type of a variable/index.js: -------------------------------------------------------------------------------- 1 | let seven = 7; 2 | let three = "3"; 3 | console.log(seven + three); 4 | // Add your code below this line 5 | console.log(typeof seven) 6 | console.log(typeof three) -------------------------------------------------------------------------------- /Debugging/04 catch misspelled variable and function names/catchmisspelledwords.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The `console.log()` and `typeof` methods are the two primary ways to check intermediate values and types of program output. Now it's time to get into the common forms that bugs take. One syntax-level issue that fast typers can commiserate with is the humble spelling error. 4 | 5 | Transposed, missing, or mis-capitalized characters in a variable or function name will have the browser looking for an object that doesn't exist - and complain in the form of a reference error. JavaScript variable and function names are case-sensitive. 6 | 7 | :fire: 8 | 9 | Fix the two spelling errors in the code so the `netWorkingCapital` calculation works. 10 | -------------------------------------------------------------------------------- /Debugging/04 catch misspelled variable and function names/index.js: -------------------------------------------------------------------------------- 1 | let receivables = 10; 2 | let payables = 8; 3 | let netWorkingCapital = receivables - payables; 4 | console.log(`Net working capital is: ${netWorkingCapital}`); -------------------------------------------------------------------------------- /Debugging/05 catch unclosed paraentheses, brackets, braces and quotes/catchunclosed.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Another syntax error to be aware of is that all opening parentheses, brackets, curly braces, and quotes have a closing pair. Forgetting a piece tends to happen when you're editing existing code and inserting items with one of the pair types. Also, take care when nesting code blocks into others, such as adding a callback function as an argument to a method. 4 | 5 | One way to avoid this mistake is as soon as the opening character is typed, immediately include the closing match, then move the cursor back between them and continue coding. Fortunately, most modern code editors generate the second half of the pair automatically. 6 | 7 | :fire: 8 | 9 | Fix the two pair errors in the code. 10 | -------------------------------------------------------------------------------- /Debugging/05 catch unclosed paraentheses, brackets, braces and quotes/index.js: -------------------------------------------------------------------------------- 1 | let myArray = [1, 2, 3]; 2 | let arraySum = myArray.reduce((previous, current) => previous + current); 3 | console.log(`Sum of array values is: ${arraySum}`); 4 | -------------------------------------------------------------------------------- /Debugging/06 catch mixed usage of single and double quotes/index.js: -------------------------------------------------------------------------------- 1 | let innerHtml = "

Click here to return home

"; 2 | console.log(innerHtml); -------------------------------------------------------------------------------- /Debugging/07 catch use of assignment operator instead of equality operator/index.js: -------------------------------------------------------------------------------- 1 | let x = 7; 2 | let y = 9; 3 | let result = "to come"; 4 | 5 | if(x === y) { 6 | result = "Equal!"; 7 | } else { 8 | result = "Not equal!"; 9 | } 10 | 11 | console.log(result); -------------------------------------------------------------------------------- /Debugging/08 catch missing open and close parenthesis after a function call/index.js: -------------------------------------------------------------------------------- 1 | function getNine() { 2 | let x = 6; 3 | let y = 3; 4 | return x + y; 5 | } 6 | 7 | let result = getNine(); 8 | console.log(result); -------------------------------------------------------------------------------- /Debugging/09 catch arguments passed in wrong order when calling a function/catcharguments.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Continuing the discussion on calling functions, the next bug to watch out for is when a function's arguments are supplied in the incorrect order. If the arguments are different types, such as a function expecting an array and an integer, this will likely throw a runtime error. If the arguments are the same type (all integers, for example), then the logic of the code won't make sense. Make sure to supply all required arguments, in the proper order to avoid these issues. 4 | 5 | :fire: 6 | 7 | The function `raiseToPower` raises a base to an exponent. Unfortunately, it's not called properly - fix the code so the value of `power` is the expected 8. 8 | -------------------------------------------------------------------------------- /Debugging/09 catch arguments passed in wrong order when calling a function/index.js: -------------------------------------------------------------------------------- 1 | function raiseToPower(b, e) { 2 | return Math.pow(b, e); 3 | } 4 | 5 | let base = 2; 6 | let exp = 3; 7 | let power = raiseToPower(base, exp); 8 | console.log(power); -------------------------------------------------------------------------------- /Debugging/10 catch off by one errors when using indexing/index.js: -------------------------------------------------------------------------------- 1 | function countToFive() { 2 | let firstFive = "12345"; 3 | let len = firstFive.length; 4 | // Fix the line below 5 | for (let i = 0; i < len; i++) { 6 | // Do not alter code below this line 7 | console.log(firstFive[i]); 8 | } 9 | } 10 | 11 | countToFive(); -------------------------------------------------------------------------------- /Debugging/11 use caution when reinitializing variables inside a loop/index.js: -------------------------------------------------------------------------------- 1 | function zeroArray(m, n) { 2 | // Creates a 2-D array with m rows and n columns of zeroes 3 | let newArray = []; 4 | let row = []; 5 | for (let i = 0; i < m; i++) { 6 | // Adds the m-th row into newArray 7 | 8 | for (let j = 0; j < n; j++) { 9 | // Pushes n zeroes into the current row to create the columns 10 | row.push(0); 11 | } 12 | // Pushes the current row, which now has n zeroes in it, to the array 13 | newArray.push(row); 14 | row = [] 15 | } 16 | return newArray; 17 | } 18 | 19 | let matrix = zeroArray(3, 2); 20 | console.log(matrix); -------------------------------------------------------------------------------- /Debugging/12 prevent infinte loops with valid terminal condition/index.js: -------------------------------------------------------------------------------- 1 | function myFunc() { 2 | for (let i = 1; i <= 4; i += 2) { 3 | console.log("Still going!"); 4 | } 5 | } -------------------------------------------------------------------------------- /ES6/01 explore differences between the var and let keywords/index.js: -------------------------------------------------------------------------------- 1 | let catName; 2 | let quote; 3 | function catTalk() { 4 | "use strict"; 5 | 6 | catName = "Oliver"; 7 | quote = catName + " says Meow!"; 8 | 9 | } 10 | catTalk(); -------------------------------------------------------------------------------- /ES6/02 compare scopes of the var and let keywords/index.js: -------------------------------------------------------------------------------- 1 | function checkScope() { 2 | "use strict"; 3 | let i = "function scope"; 4 | if (true) { 5 | let i = "block scope"; 6 | console.log("Block scope i is: ", i); 7 | } 8 | console.log("Function scope i is: ", i); 9 | return i; 10 | } 11 | 12 | checkScope(); -------------------------------------------------------------------------------- /ES6/03 declare a read only variable with const keyword/index.js: -------------------------------------------------------------------------------- 1 | function printManyTimes(str) { 2 | "use strict"; 3 | 4 | // change code below this line 5 | 6 | const SENTENCE = str + " is cool!"; 7 | for(let i = 0; i < str.length; i+=2) { 8 | console.log(SENTENCE); 9 | } 10 | 11 | // change code above this line 12 | 13 | } 14 | printManyTimes("freeCodeCamp"); -------------------------------------------------------------------------------- /ES6/04 mutate an array declared with const/index.js: -------------------------------------------------------------------------------- 1 | const s = [5, 7, 2]; 2 | function editInPlace() { 3 | "use strict"; 4 | // change code below this line 5 | 6 | // s = [2, 5, 7]; <- this is invalid 7 | s[0] = 2; 8 | s[1] = 5; 9 | s[2] = 7; 10 | // change code above this line 11 | } 12 | editInPlace(); -------------------------------------------------------------------------------- /ES6/06 use arrow functions to write concise anonymous functions/index.js: -------------------------------------------------------------------------------- 1 | const magic = () => new Date(); 2 | -------------------------------------------------------------------------------- /ES6/07 write arrow functions woth parameters/arrowfuntionswithparameter.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Just like a normal function, you can pass arguments into arrow functions. 4 | 5 | ```javascript 6 | // doubles input value and returns it 7 | const doubler = (item) => item * 2; 8 | You can pass more than one argument into arrow functions as well. 9 | ``` 10 | 11 | :fire: 12 | 13 | Rewrite the `myConcat` function which appends contents of `arr2` to `arr1` so that the function uses arrow function syntax. 14 | -------------------------------------------------------------------------------- /ES6/07 write arrow functions woth parameters/index.js: -------------------------------------------------------------------------------- 1 | const myConcat = (arr1, arr2) => arr1.concat(arr2); 2 | 3 | // test your code 4 | console.log(myConcat([1, 2], [3, 4, 5])); 5 | -------------------------------------------------------------------------------- /ES6/08 write higher order arrow functions/index.js: -------------------------------------------------------------------------------- 1 | const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2]; 2 | const squareList = arr => { 3 | "use strict"; 4 | // change code below this line 5 | const squaredIntegers = arr.filter( (num) => num > 0 && num % parseInt(num) === 0 ).map( (num) => Math.pow(num, 2) ); 6 | // change code above this line 7 | return squaredIntegers; 8 | }; 9 | // test your code 10 | const squaredIntegers = squareList(realNumberArray); 11 | console.log(squaredIntegers); 12 | -------------------------------------------------------------------------------- /ES6/09 set default parameters for your functions/index.js: -------------------------------------------------------------------------------- 1 | const increment = (function() { 2 | "use strict"; 3 | return function increment(number, value = 1) { 4 | return number + value; 5 | }; 6 | })(); 7 | console.log(increment(5, 2)); // returns 7 8 | console.log(increment(5)); // returns 6 9 | -------------------------------------------------------------------------------- /ES6/10 use the rest operator with funtion parameters/index.js: -------------------------------------------------------------------------------- 1 | const sum = (function() { 2 | "use strict"; 3 | return function sum(...args) { 4 | return args.reduce((a, b) => a + b, 0); 5 | }; 6 | })(); 7 | console.log(sum(1, 2, 3)); // 6 -------------------------------------------------------------------------------- /ES6/11 use spread operator to evaluate arrays in-place/index.js: -------------------------------------------------------------------------------- 1 | const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY']; 2 | let arr2; 3 | (function() { 4 | "use strict"; 5 | arr2 = [...arr1]; // change this line 6 | })(); 7 | console.log(arr2); -------------------------------------------------------------------------------- /ES6/12 use destructing assignment to assign variables from objects/index.js: -------------------------------------------------------------------------------- 1 | const AVG_TEMPERATURES = { 2 | today: 77.5, 3 | tomorrow: 79 4 | }; 5 | 6 | function getTempOfTmrw(avgTemperatures) { 7 | "use strict"; 8 | // change code below this line 9 | const {tomorrow: tempOfTomorrow} = avgTemperatures; // change this line 10 | // change code above this line 11 | return tempOfTomorrow; 12 | } 13 | 14 | console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79 -------------------------------------------------------------------------------- /ES6/13 use destruturing assignment to assign variables from nested objects/index.js: -------------------------------------------------------------------------------- 1 | const LOCAL_FORECAST = { 2 | today: { min: 72, max: 83 }, 3 | tomorrow: { min: 73.3, max: 84.6 } 4 | }; 5 | 6 | function getMaxOfTmrw(forecast) { 7 | "use strict"; 8 | // change code below this line 9 | const {tomorrow:{max:maxOfTomorrow}} = forecast; // change this line 10 | // change code above this line 11 | return maxOfTomorrow; 12 | } 13 | 14 | console.log(getMaxOfTmrw(LOCAL_FORECAST)); // should be 84.6 -------------------------------------------------------------------------------- /ES6/13 use destruturing assignment to assign variables from nested objects/nesteddestructing.md: -------------------------------------------------------------------------------- 1 | :coffee: :star: 2 | 3 | We can similarly destructure _nested_ objects into variables. 4 | 5 | :zap: Consider the following code: 6 | 7 | ```javascript 8 | const a = { 9 | start: { x: 5, y: 6 }, 10 | end: { x: 6, y: -9 } 11 | }; 12 | const { 13 | start: { x: startX, y: startY } 14 | } = a; 15 | console.log(startX, startY); // 5, 6 16 | ``` 17 | 18 | In the example above, the variable start is assigned the value of a.start, which is also an object. 19 | 20 | :fire: 21 | 22 | Use destructuring assignment to obtain `max` of `forecast.tomorrow` and assign it to `maxOfTomorrow`. 23 | -------------------------------------------------------------------------------- /ES6/14 use destructing assignments to assign varibles from arrays/index.js: -------------------------------------------------------------------------------- 1 | let a = 8, 2 | b = 6; 3 | (() => { 4 | "use strict"; 5 | // change code below this line 6 | [b, a] = [a, b]; 7 | // change code above this line 8 | })(); 9 | console.log(a); // should be 6 10 | console.log(b); // should be 8 11 | -------------------------------------------------------------------------------- /ES6/15 use destructing assignment with the rest operator to reassign array elements/index.js: -------------------------------------------------------------------------------- 1 | const source = [1,2,3,4,5,6,7,8,9,10]; 2 | function removeFirstTwo(list) { 3 | "use strict"; 4 | // change code below this line 5 | const [a, b, ...arr] = list; // change this 6 | // change code above this line 7 | return arr; 8 | } 9 | const arr = removeFirstTwo(source); 10 | console.log(arr); // should be [3,4,5,6,7,8,9,10] 11 | console.log(source); // should be [1,2,3,4,5,6,7,8,9,10]; -------------------------------------------------------------------------------- /ES6/16 use destructing assignment to pass an object as a funtion parameters/index.js: -------------------------------------------------------------------------------- 1 | const stats = { 2 | max: 56.78, 3 | standard_deviation: 4.34, 4 | median: 34.54, 5 | mode: 23.87, 6 | min: -0.75, 7 | average: 35.85 8 | }; 9 | const half = (function() { 10 | "use strict"; // do not change this line 11 | 12 | // change code below this line 13 | return function half({ max, min }) { 14 | // use function argument destructuring 15 | return (max + min) / 2.0; 16 | }; 17 | // change code above this line 18 | })(); 19 | console.log(stats); // should be object 20 | console.log(half(stats)); // should be 28.015 21 | -------------------------------------------------------------------------------- /ES6/18 write concise object literal declarations using simple fields/index.js: -------------------------------------------------------------------------------- 1 | const createPerson = (name, age, gender) => { 2 | "use strict"; 3 | // change code below this line 4 | return { 5 | name, 6 | age, 7 | gender 8 | }; 9 | // change code above this line 10 | }; 11 | console.log(createPerson("Zodiac Hasbro", 56, "male")); // returns a proper object 12 | -------------------------------------------------------------------------------- /ES6/19 write concise declarative functions with es6/declartivefunctions.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | When defining functions within objects in ES5, we have to use the keyword `function` as follows: 4 | 5 | ```js 6 | const person = { 7 | name: "Taylor", 8 | sayHello: function() { 9 | return `Hello! My name is ${this.name}.`; 10 | } 11 | }; 12 | ``` 13 | 14 | :black_heart: With ES6, You can remove the function keyword and colon altogether when defining functions in objects. Here's an example of this syntax: 15 | 16 | ```js 17 | const person = { 18 | name: "Taylor", 19 | sayHello() { 20 | return `Hello! My name is ${this.name}.`; 21 | } 22 | }; 23 | ``` 24 | 25 | :fire: 26 | 27 | Refactor the function `setGear` inside the object `bicycle` to use the shorthand syntax described above. 28 | -------------------------------------------------------------------------------- /ES6/19 write concise declarative functions with es6/index.js: -------------------------------------------------------------------------------- 1 | // change code below this line 2 | const bicycle = { 3 | gear: 2, 4 | setGear(newGear) { 5 | "use strict"; 6 | this.gear = newGear; 7 | } 8 | }; 9 | // change code above this line 10 | bicycle.setGear(3); 11 | console.log(bicycle.gear); 12 | -------------------------------------------------------------------------------- /ES6/20 use class syntax to define constructor function/index.js: -------------------------------------------------------------------------------- 1 | function makeClass() { 2 | "use strict"; 3 | /* Alter code below this line */ 4 | class Vegetable { 5 | constructor(name) { 6 | this.name = name; 7 | } 8 | } 9 | /* Alter code above this line */ 10 | return Vegetable; 11 | } 12 | const Vegetable = makeClass(); 13 | const carrot = new Vegetable("carrot"); 14 | console.log(carrot.name); // => should be 'carrot' 15 | -------------------------------------------------------------------------------- /ES6/21 use getters and setters to control access to an object/index.js: -------------------------------------------------------------------------------- 1 | function makeClass() { 2 | "use strict"; 3 | /* Alter code below this line */ 4 | class Thermostat { 5 | constructor(farenheit) { 6 | this.farenheit = farenheit; 7 | } 8 | 9 | get temperature() { 10 | return (5 / 9) * (this.farenheit - 32); 11 | } 12 | 13 | set temperature(celsius) { 14 | this.farenheit = (celsius * 9.0) / 5 + 32; 15 | } 16 | } 17 | /* Alter code above this line */ 18 | return Thermostat; 19 | } 20 | const Thermostat = makeClass(); 21 | const thermos = new Thermostat(76); // setting in Fahrenheit scale 22 | let temp = thermos.temperature; // 24.44 in C 23 | thermos.temperature = 26; 24 | temp = thermos.temperature; // 26 in C 25 | -------------------------------------------------------------------------------- /ES6/22 understand differences between import and require/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | import { capitalizeString } from "string_functions"; 3 | 4 | capitalizeString("hello!"); 5 | -------------------------------------------------------------------------------- /ES6/23 use export to reuse a code block/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | export const foo = "bar"; 3 | export const bar = "foo"; 4 | -------------------------------------------------------------------------------- /ES6/24 use * to import everyting from a file/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | import * as str from "capitalize_strings"; 4 | -------------------------------------------------------------------------------- /ES6/25 create an export fallback with export default/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | function subtract(x, y) { 3 | return x - y; 4 | } 5 | 6 | export default subtract; 7 | -------------------------------------------------------------------------------- /ES6/26 import a default export/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | import subtract from "./"; 3 | 4 | subtract(7, 4); 5 | -------------------------------------------------------------------------------- /Functional Programming/01 learn about functional programming/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A long process to prepare tea. 3 | * @return {string} A cup of tea. 4 | **/ 5 | const prepareTea = () => 'greenTea'; 6 | 7 | /** 8 | * Get given number of cups of tea. 9 | * @param {number} numOfCups Number of required cups of tea. 10 | * @return {Array} Given amount of tea cups. 11 | **/ 12 | const getTea = (numOfCups) => { 13 | const teaCups = []; 14 | 15 | for(let cups = 1; cups <= numOfCups; cups += 1) { 16 | const teaCup = prepareTea(); 17 | teaCups.push(teaCup); 18 | } 19 | 20 | return teaCups; 21 | }; 22 | 23 | // Add your code below this line 24 | 25 | const tea4TeamFCC = getTea(40); // :( 26 | 27 | // Add your code above this line 28 | 29 | console.log(tea4TeamFCC); -------------------------------------------------------------------------------- /Functional Programming/04 avoid mutations and side effects using functional programming/index.js: -------------------------------------------------------------------------------- 1 | // the global variable 2 | var fixedValue = 4; 3 | 4 | function incrementer() { 5 | // Add your code below this line 6 | console.log(fixedValue); 7 | return fixedValue + 1; 8 | 9 | // Add your code above this line 10 | } 11 | 12 | var newValue = incrementer(); // Should equal 5 13 | console.log(newValue); 14 | console.log(fixedValue); // Should print 4 15 | -------------------------------------------------------------------------------- /Functional Programming/05 pass arguments to avoid external dependence in a function/index.js: -------------------------------------------------------------------------------- 1 | // the global variable 2 | var fixedValue = 4; 3 | 4 | // Add your code below this line 5 | function incrementer(val) { 6 | console.log(fixedValue === val++); 7 | let newVal = val + 1; 8 | console.log(fixedValue === newVal); 9 | return val + 1; 10 | // Add your code above this line 11 | } 12 | 13 | var newValue = incrementer(fixedValue); // Should equal 5 14 | console.log(newValue); 15 | console.log(fixedValue); // Should print 4 16 | -------------------------------------------------------------------------------- /Functional Programming/08 implement map on a prototype/index.js: -------------------------------------------------------------------------------- 1 | // the global Array 2 | var s = [23, 65, 98, 5]; 3 | 4 | Array.prototype.myMap = function(callback) { 5 | var newArray = []; 6 | // console.log(this); 7 | // Add your code below this line 8 | for (let i = 0; i < this.length; i++) { 9 | newArray.push(callback(this[i], i, this)); 10 | } 11 | 12 | // Add your code above this line 13 | return newArray; 14 | }; 15 | 16 | var new_s = s.myMap(function(item) { 17 | return item * 2; 18 | }); 19 | 20 | console.log(new_s); 21 | -------------------------------------------------------------------------------- /Functional Programming/10 implement the filter method on a prototype/filterprototype.md: -------------------------------------------------------------------------------- 1 | :coffee: :star: 2 | 3 | It would teach us a lot about the `filter` method if we try to implement a version of it that behaves exactly like `Array.prototype.filter()`. It can use either a `for` loop or `Array.prototype.forEach()`. 4 | 5 | Note: A pure function is allowed to alter local variables defined within its scope, although, it's preferable to avoid that as well. 6 | 7 | :fire: 8 | 9 | Write your own `Array.prototype.myFilter()`, which should behave exactly like `Array.prototype.filter()`. You may use a `for` loop or the `Array.prototype.forEach()` method. 10 | -------------------------------------------------------------------------------- /Functional Programming/10 implement the filter method on a prototype/index.js: -------------------------------------------------------------------------------- 1 | // the global Array 2 | var s = [23, 65, 98, 5]; 3 | 4 | Array.prototype.myFilter = function(callback, context) { 5 | var newArray = []; 6 | // Add your code below this line 7 | for (let i = 0; i < this.length; i++) { 8 | if (callback.call(context, this[i], i, this)) { 9 | newArray.push(this[i]); 10 | } 11 | } 12 | // Add your code above this line 13 | return newArray; 14 | }; 15 | 16 | var new_s = s.myFilter(function(item) { 17 | return item % 2 === 1; 18 | }); 19 | 20 | console.log(new_s); 21 | -------------------------------------------------------------------------------- /Functional Programming/11 return part of an array using slice method/index.js: -------------------------------------------------------------------------------- 1 | function sliceArray(anim, beginSlice, endSlice) { 2 | // Add your code below this line 3 | return anim.slice(beginSlice, endSlice); 4 | // Add your code above this line 5 | } 6 | var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"]; 7 | sliceArray(inputAnim, 1, 3); 8 | -------------------------------------------------------------------------------- /Functional Programming/12 remove elements from an array using slice instead of splice/index.js: -------------------------------------------------------------------------------- 1 | function nonMutatingSplice(cities) { 2 | // Add your code below this line 3 | return cities.slice(0, 3); 4 | 5 | // Add your code above this line 6 | } 7 | var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"]; 8 | nonMutatingSplice(inputCities); 9 | -------------------------------------------------------------------------------- /Functional Programming/13 combine two arrays using concat method/concat.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | _Concatenation_ means to join items end to end. JavaScript offers the `concat` method for both strings and arrays that work in the same way. For arrays, the method is called on one, then another array is provided as the argument to concat, which is added to the end of the first array. It returns a new array and does not mutate either of the original arrays. Here's an example: 4 | 5 | ```js 6 | [1, 2, 3].concat([4, 5, 6]); 7 | // Returns a new array [1, 2, 3, 4, 5, 6] 8 | ``` 9 | 10 | :fire: 11 | 12 | Use the `concat` method in the `nonMutatingConcat` function to concatenate `attach` to the end of `original`. The function should return the concatenated array. 13 | -------------------------------------------------------------------------------- /Functional Programming/13 combine two arrays using concat method/index.js: -------------------------------------------------------------------------------- 1 | function nonMutatingConcat(original, attach) { 2 | // Add your code below this line 3 | return original.concat(attach); 4 | 5 | // Add your code above this line 6 | } 7 | var first = [1, 2, 3]; 8 | var second = [4, 5]; 9 | nonMutatingConcat(first, second); 10 | -------------------------------------------------------------------------------- /Functional Programming/14 add elements to the end of an array using concat instead of push/index.js: -------------------------------------------------------------------------------- 1 | function nonMutatingPush(original, newItem) { 2 | // Add your code below this line 3 | return original.concat(newItem); 4 | 5 | // Add your code above this line 6 | } 7 | var first = [1, 2, 3]; 8 | var second = [4, 5]; 9 | nonMutatingPush(first, second); -------------------------------------------------------------------------------- /Functional Programming/16 sort an array alphabetically using the sort method/index.js: -------------------------------------------------------------------------------- 1 | function alphabeticalOrder(arr) { 2 | // Add your code below this line 3 | return arr.sort(function(a, b) { 4 | if (a < b) { 5 | return -1; 6 | } else if (a > b) { 7 | return 1; 8 | } else { 9 | return 0; 10 | } 11 | }); 12 | // Add your code above this line 13 | } 14 | console.log(alphabeticalOrder(["a", "d", "c", "a", "z", "g"])); 15 | -------------------------------------------------------------------------------- /Functional Programming/17 return a sorted array without changing the original array/index.js: -------------------------------------------------------------------------------- 1 | var globalArray = [5, 6, 3, 2, 9]; 2 | function nonMutatingSort(arr) { 3 | // Add your code below this line 4 | return arr.concat().sort(function(a, b) { 5 | if (a < b) return -1; 6 | else if (a > b) return 1; 7 | else return 0; 8 | }); 9 | 10 | // Add your code above this line 11 | } 12 | nonMutatingSort(globalArray); 13 | -------------------------------------------------------------------------------- /Functional Programming/17 return a sorted array without changing the original array/returnsortedarraywithoutchange.md: -------------------------------------------------------------------------------- 1 | :coffee: :star: 2 | 3 | A side effect of the `sort` method is that it changes the order of the elements in the original array. In other words, it mutates the array in place. One way to avoid this is to first `concatenate` an empty array to the one being sorted (remember that concat returns a new array), then run the sort method. 4 | 5 | :fire: 6 | 7 | Use the `sort` method in the `nonMutatingSort` function to sort the elements of an array in ascending order. The function should return a new array, and not mutate the `globalArray` variable. 8 | -------------------------------------------------------------------------------- /Functional Programming/18 split a string into an array using the split method/index.js: -------------------------------------------------------------------------------- 1 | function splitify(str) { 2 | // Add your code below this line 3 | return str.split(/\W/); 4 | // Add your code above this line 5 | } 6 | console.log(splitify("Hello World,I-am code")); 7 | -------------------------------------------------------------------------------- /Functional Programming/19 combine an array into a string using the join method/index.js: -------------------------------------------------------------------------------- 1 | function sentensify(str) { 2 | // Add your code below this line 3 | return str.split(/\W/).join(" "); 4 | // Add your code above this line 5 | } 6 | console.log(sentensify("May-the-force-be-with-you")); 7 | -------------------------------------------------------------------------------- /Functional Programming/19 combine an array into a string using the join method/join.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The `join` method is used to join the elements of an array together to create a string. It takes an argument for the delimiter that is used to separate the array elements in the string. 4 | 5 | Here's an example: 6 | 7 | ```js 8 | var arr = ["Hello", "World"]; 9 | var str = arr.join(" "); 10 | // Sets str to "Hello World" 11 | ``` 12 | 13 | :fire: 14 | 15 | Use the `join` method (among others) inside the `sentensify` function to make a sentence from the words in the string `str`. The function should return a string. For example, "I-like-Star-Wars" would be converted to "I like Star Wars". For this challenge, do not use the `replace` method. 16 | -------------------------------------------------------------------------------- /Functional Programming/20 apply functional programming to convert string to url slugs/index.js: -------------------------------------------------------------------------------- 1 | // the global variable 2 | var globalTitle = "A Mind Needs Books Like A Sword Needs A Whetstone"; 3 | 4 | // Add your code below this line 5 | function urlSlug(title) { 6 | let myTitle = title.concat(""); 7 | return myTitle 8 | .toLowerCase() 9 | .trim() 10 | .split(/\s+/) 11 | .join("-"); 12 | } 13 | // Add your code above this line 14 | 15 | var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming" 16 | console.log(winterComing); 17 | console.log(globalTitle); 18 | -------------------------------------------------------------------------------- /Functional Programming/21 use the every method to check that evert element in an array meets a criteria/every.md: -------------------------------------------------------------------------------- 1 | :coffee: :star: 2 | 3 | The every `method` works with arrays to check if every element passes a particular test. It returns a Boolean value - `true` if all values meet the criteria, `false` if not. 4 | 5 | For example, the following code would check if every element in the numbers array is less than 10: 6 | 7 | ```js 8 | var numbers = [1, 5, 8, 0, 10, 11]; 9 | numbers.every(function(currentValue) { 10 | return currentValue < 10; 11 | }); 12 | // Returns false 13 | ``` 14 | 15 | :fire: 16 | 17 | Use the `every` method inside the `checkPositive` function to check if every element in `arr` is positive. The function should return a Boolean value. 18 | -------------------------------------------------------------------------------- /Functional Programming/21 use the every method to check that evert element in an array meets a criteria/index.js: -------------------------------------------------------------------------------- 1 | function checkPositive(arr) { 2 | // Add your code below this line 3 | 4 | return arr.every(function(a) { 5 | return a > 0; 6 | }); 7 | // Add your code above this line 8 | } 9 | checkPositive([1, 2, 3, -4, 5]); 10 | -------------------------------------------------------------------------------- /Functional Programming/22 use the some method to check that any elements in an array meet a crietria/index.js: -------------------------------------------------------------------------------- 1 | function checkPositive(arr) { 2 | // Add your code below this line 3 | 4 | return arr.some(function(a) { 5 | return a > 0; 6 | }); 7 | // Add your code above this line 8 | } 9 | checkPositive([1, 2, 3, -4, 5]); 10 | -------------------------------------------------------------------------------- /Functional Programming/22 use the some method to check that any elements in an array meet a crietria/some.md: -------------------------------------------------------------------------------- 1 | :coffee: :star: 2 | 3 | The `some` method works with arrays to check if any element passes a particular test. It returns a Boolean value - `true` if any of the values meet the criteria, `false` if not. 4 | 5 | For example, the following code would check if any element in the numbers array is less than 10: 6 | 7 | ```js 8 | var numbers = [10, 50, 8, 220, 110, 11]; 9 | numbers.some(function(currentValue) { 10 | return currentValue < 10; 11 | }); 12 | // Returns true 13 | ``` 14 | 15 | :fire: 16 | 17 | Use the `some` method inside the `checkPositive` function to check if any element in arr is positive. The function should return a Boolean value. 18 | -------------------------------------------------------------------------------- /Functional Programming/23 introduction to currying and partial appllication/index.js: -------------------------------------------------------------------------------- 1 | function add(x) { 2 | // Add your code below this line 3 | return function(y) { 4 | return function(z) { 5 | return x + y + z; 6 | }; 7 | }; 8 | 9 | // Add your code above this line 10 | } 11 | add(10)(20)(30); 12 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/01 sum of all numbers in a range/indes.js: -------------------------------------------------------------------------------- 1 | function sumAll(arr) { 2 | let min = Math.min(...arr); 3 | let max = Math.max(...arr); 4 | console.log(min); 5 | console.log(max); 6 | 7 | let tempArr = []; 8 | for (let i = min; i <= max; i++) { 9 | tempArr.push(i); 10 | } 11 | console.log(tempArr); 12 | return tempArr.reduce((a, b) => a + b); 13 | } 14 | 15 | console.log(sumAll([1, 4])); 16 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/01 sum of all numbers in a range/sumofallnumbers.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | We'll pass you an array of two numbers. Return the sum of those two numbers plus the sum of all the numbers between them. 4 | 5 | The lowest number will not always come first. 6 | 7 | Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code. -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/02 diff two arrays/diffarray.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays. 4 | 5 | Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code. 6 | 7 | Note 8 | You can return the array with its elements in any order. -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/02 diff two arrays/index.js: -------------------------------------------------------------------------------- 1 | function diffArray(arr1, arr2) { 2 | let newArr = []; 3 | arr1.map(function(num) { 4 | if (!arr2.includes(num)) { 5 | console.log(num); 6 | newArr.push(num); 7 | } 8 | }); 9 | 10 | arr2.map(function(num) { 11 | if (!arr1.includes(num)) { 12 | console.log(num); 13 | newArr.push(num); 14 | } 15 | }); 16 | console.log(newArr); 17 | return newArr; 18 | } 19 | 20 | console.log(diffArray([1, "calf", 3, "piglet"], [1, "calf", 3, 4])); 21 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/03 seek and destroy/index.js: -------------------------------------------------------------------------------- 1 | function destroyer(arr) { 2 | var args = Array.prototype.slice.call(arguments); 3 | 4 | for (var i = 0; i < arr.length; i++) { 5 | for (var j = 0; j < args.length; j++) { 6 | if (arr[i] === args[j]) { 7 | delete arr[i]; 8 | } 9 | } 10 | } 11 | return arr.filter(Boolean); 12 | } 13 | 14 | console.log(destroyer([1, 2, 3, 1, 2, 3], 2, 3)); 15 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/03 seek and destroy/seekanddestroy.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments. 4 | 5 | Note 6 | You have to use the arguments object. 7 | 8 | Remember to use Read-Search-Ask if you get stuck. Write your own code. 9 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/04 wherefore atr thou/index.js: -------------------------------------------------------------------------------- 1 | function whatIsInAName(collection, source) { 2 | // What's in a name? 3 | var arr = []; 4 | // Only change code below this line 5 | const sourceKeys = Object.keys(source); 6 | console.log(sourceKeys); 7 | return collection.filter(function(item) { 8 | return sourceKeys.every(function(k) { 9 | return item[k] === source[k]; 10 | }); 11 | }); 12 | 13 | // Only change code above this line 14 | return arr; 15 | } 16 | 17 | console.log( 18 | whatIsInAName( 19 | [ 20 | { apple: 1, bat: 2 }, 21 | { apple: 1 }, 22 | { apple: 1, bat: 2, cookie: 2 }, 23 | { bat: 2 } 24 | ], 25 | { apple: 1, bat: 2 } 26 | ) 27 | ); 28 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/04 wherefore atr thou/whereforeatrthou.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: :star: 2 | 3 | Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching name and value pairs (second argument). Each name and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array. 4 | 5 | For example, if the first argument is `[{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }]`, and the second argument is `{ last: "Capulet" }`, then you must return the third object from the array (the first argument), because it contains the name and its value, that was passed on as the second argument 6 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/05 spinal tap case/index.js: -------------------------------------------------------------------------------- 1 | function spinalCase(str) { 2 | // "It's such a fine line between stupid, and clever." 3 | // --David St. Hubbins 4 | let regex = /\s+|_+/g; 5 | str = str.replace(/([a-z])([A-Z])/g, "$1 $2"); 6 | return str.replace(regex, "-").toLowerCase(); 7 | 8 | return str; 9 | } 10 | 11 | console.log(spinalCase("AllThe-small Things")); 12 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/05 spinal tap case/spinaltapcase.md: -------------------------------------------------------------------------------- 1 | :coffee: :sweat: 2 | 3 | Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes. 4 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/06 pig latin/index.js: -------------------------------------------------------------------------------- 1 | function translatePigLatin(str) { 2 | let pigLatin = ""; 3 | let regex = /[aeiou]/gi; 4 | if (str[0].match(regex)) { 5 | pigLatin = str + "way"; 6 | } else if (str.match(regex) === null) { 7 | pigLatin = str + "ay"; 8 | } else { 9 | console.log(str.match(regex)[0]); 10 | let vowelIndex = str.indexOf(str.match(regex)[0]); 11 | pigLatin = str.substr(vowelIndex) + str.substr(0, vowelIndex) + "ay"; 12 | } 13 | return pigLatin; 14 | } 15 | 16 | function isVowel(l) { 17 | return l === "a" || l === "e" || l === "i" || l === "o" || l === "u"; 18 | } 19 | 20 | translatePigLatin("consonant"); 21 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/06 pig latin/piglatin.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Translate the provided string to pig latin. 4 | 5 | Pig Latin takes the first consonant (or consonant cluster) of an English word, moves it to the end of the word and suffixes an "ay". 6 | 7 | If a word begins with a vowel you just add "way" to the end. 8 | 9 | Input strings are guaranteed to be English words in all lowercase. 10 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/07 search and replace/index.js: -------------------------------------------------------------------------------- 1 | function myReplace(str, before, after) { 2 | const strArr = str.split(" "); 3 | let index = null; 4 | strArr.includes(before) ? (index = strArr.indexOf(before)) : null; 5 | console.log(index); 6 | 7 | str[index] === str[index].toUpperCase() 8 | ? (after = after.charAt(0).toUpperCase() + after.slice(1)) 9 | : null; 10 | 11 | str = str.replace(before, after); 12 | return str; 13 | } 14 | 15 | console.log( 16 | // myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped") 17 | myReplace("His name is Tom", "Tom", "john") 18 | ); 19 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/07 search and replace/searchandreplace.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Perform a search and replace on the sentence using the arguments provided and return the new sentence. 4 | 5 | First argument is the sentence to perform the search and replace on. 6 | 7 | Second argument is the word that you will be replacing (before). 8 | 9 | Third argument is what you will be replacing the second argument with (after). 10 | 11 | Note 12 | Preserve the case of the first character in the original word when you are replacing it. For example if you mean to replace the word "Book" with the word "dog", it should be replaced as "Dog" 13 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/08 dna pairing/dnapairing.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: :sweat: 2 | 3 | The DNA strand is missing the pairing element. Take each character, get its pair, and return the results as a 2d array. 4 | 5 | Base pairs are a pair of AT and CG. Match the missing element to the provided character. 6 | 7 | Return the provided character as the first element in each array. 8 | 9 | For example, for the input GCG, return [["G", "C"], ["C","G"],["G", "C"]] 10 | 11 | The character and its pair are paired up in an array, and all the arrays are grouped into one encapsulating array. 12 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/09 missing letters/index.js: -------------------------------------------------------------------------------- 1 | function fearNotLetter(str) { 2 | for (let i = 0; i < str.length; i++) { 3 | let code = str.charCodeAt(i); 4 | // If code of current character is not equal to first character + no of iterations, 5 | // hence character has been escaped. 6 | if (code != str.charCodeAt(0) + i) { 7 | return String.fromCharCode(code - 1); 8 | } 9 | } 10 | return undefined; 11 | } 12 | 13 | console.log(fearNotLetter("abce")); 14 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/09 missing letters/missingletter.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Find the missing letter in the passed letter range and return it. 4 | 5 | If all letters are present in the range, return undefined. 6 | 7 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/10 sorted union/index.js: -------------------------------------------------------------------------------- 1 | function uniteUnique(...args) { 2 | console.log(args); 3 | let result = []; 4 | for (var i = 0; i < args.length; i++) { 5 | for (var j = 0; j < args[i].length; j++) { 6 | if (!result.includes(args[i][j])) { 7 | result.push(args[i][j]); 8 | } 9 | } 10 | } 11 | return result; 12 | } 13 | 14 | console.log(uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1])); 15 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/10 sorted union/sortedunion.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Write a function that takes two or more arrays and returns a new array of unique values in the order of the original provided arrays. 4 | 5 | In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array. 6 | 7 | The unique numbers should be sorted by their original order, but the final array should not be sorted in numerical order. 8 | 9 | Check the assertion tests for examples. -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/11 convert html entities/converthtmlentites.md: -------------------------------------------------------------------------------- 1 | :coffee: :sweat: 2 | 3 | Convert the characters &, <, >, " (double quote), and ' (apostrophe), in a string to their corresponding HTML entities. 4 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/12 sum all odd fibonacci numbers/sumofoddfibinaccinumbers.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: :sweat: 2 | 3 | Given a positive integer num, return the sum of all odd Fibonacci numbers that are less than or equal to num. 4 | 5 | The first two numbers in the Fibonacci sequence are 1 and 1. Every additional number in the sequence is the sum of the two previous numbers. The first six numbers of the Fibonacci sequence are 1, 1, 2, 3, 5 and 8. 6 | 7 | For example, sumFibs(10) should return 10 because all odd Fibonacci numbers less than or equal to 10 are 1, 1, 3, and 5. 8 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/13 sum of all primes/sumofallprimers.md: -------------------------------------------------------------------------------- 1 | :coffee: :sweat: 2 | 3 | Sum all the prime numbers up to and including the provided number. 4 | 5 | A prime number is defined as a number greater than one and having only two divisors, one and itself. For example, 2 is a prime number because it's only divisible by one and two. 6 | 7 | The provided number may not be a prime. 8 | 9 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/14 smallest common multiple/index.js: -------------------------------------------------------------------------------- 1 | function smallestCommons(arr) { 2 | var range = []; 3 | for (var i = Math.max(arr[0], arr[1]); i >= Math.min(arr[0], arr[1]); i--) { 4 | range.push(i); 5 | } 6 | 7 | // can use reduce() in place of this block 8 | var lcm = range[0]; 9 | for (i = 1; i < range.length; i++) { 10 | var GCD = gcd(lcm, range[i]); 11 | lcm = (lcm * range[i]) / GCD; 12 | } 13 | return lcm; 14 | 15 | function gcd(x, y) { // Implements the Euclidean Algorithm 16 | if (y === 0) 17 | return x; 18 | else 19 | return gcd(y, x%y); 20 | } 21 | } 22 | 23 | // test here 24 | smallestCommons([1,5]); -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/14 smallest common multiple/smallestcommonmultiple.md: -------------------------------------------------------------------------------- 1 | :coffee: :sweat: 2 | 3 | Find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters. 4 | 5 | The range will be an array of two numbers that will not necessarily be in numerical order. 6 | 7 | For example, if given 1 and 3, find the smallest common multiple of both 1 and 3 that is also evenly divisible by all numbers between 1 and 3. The answer here would be 6. 8 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/15 drop it/dropit.md: -------------------------------------------------------------------------------- 1 | :coffee: :sweat: 2 | 3 | Given the array arr, iterate through and remove each element starting from the first element (the 0 index) until the function func returns true when the iterated element is passed through it. 4 | 5 | Then return the rest of the array once the condition is satisfied, otherwise, arr should be returned as an empty array. -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/15 drop it/index.js: -------------------------------------------------------------------------------- 1 | // function dropElements(arr, func) { 2 | // let dropItArr = []; 3 | // for (let i = 0; i < arr.length; i++) { 4 | // console.log(arr[i]); 5 | // func(arr[i]) ? null : dropItArr.push(arr[i]); 6 | // } 7 | // // Drop them elements. 8 | // return dropItArr; 9 | // } 10 | 11 | // console.log( 12 | // dropElements([1, 2, 3, 9, 2], function(n) { 13 | // return n > 2; 14 | // }) 15 | // ); 16 | 17 | function dropElements(arr, func) { 18 | return arr.slice( 19 | arr.findIndex(func) >= 0 ? arr.findIndex(func) : arr.length, 20 | arr.length 21 | ); 22 | } 23 | 24 | // test here 25 | console.log( 26 | dropElements([1, 2, 3, 4], function(n) { 27 | return n >= 3; 28 | }) 29 | ); 30 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/16 steamroller/index.js: -------------------------------------------------------------------------------- 1 | function steamrollArray(arr) { 2 | var flattenedArray = []; 3 | 4 | // Create function that adds an element if it is not an array. 5 | // If it is an array, then loops through it and uses recursion on that array. 6 | var flatten = function(arg) { 7 | if (!Array.isArray(arg)) { 8 | flattenedArray.push(arg); 9 | } else { 10 | for (var a in arg) { 11 | flatten(arg[a]); 12 | } 13 | } 14 | }; 15 | 16 | // Call the function for each element in the array 17 | arr.forEach(flatten); 18 | return flattenedArray; 19 | } 20 | 21 | // test here 22 | console.log(steamrollArray([1, [2], [3, [[4]]]])); 23 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/16 steamroller/steamroller.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Flatten a nested array. You must account for varying levels of nesting. 4 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/17 binary agents/binary.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Return an English translated sentence of the passed binary string. 4 | 5 | The binary string will be space separated. 6 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/17 binary agents/index.js: -------------------------------------------------------------------------------- 1 | function binaryAgent(str) { 2 | return String.fromCharCode( 3 | ...str.split(" ").map(function(char) { 4 | return parseInt(char, 2); 5 | }) 6 | ); 7 | } 8 | 9 | console.log( 10 | binaryAgent( 11 | "01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111" 12 | ) 13 | ); 14 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/18 everything be true/everythingbetrue.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Check if the predicate (second argument) is truthy on all elements of a collection (first argument). 4 | 5 | In other words, you are given an array collection of objects. The predicate pre will be an object property and you need to return true if its value is truthy. Otherwise, return false. 6 | 7 | In JavaScript, truthy values are values that translate to true when evaluated in a Boolean context. 8 | 9 | Remember, you can access object properties through either dot notation or [] notation. 10 | 11 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/18 everything be true/index.js: -------------------------------------------------------------------------------- 1 | function truthCheck(collection, pre) { 2 | return collection.every(function(element) { 3 | return element.hasOwnProperty(pre) && Boolean(element[pre]); 4 | }); 5 | } 6 | 7 | console.log( 8 | truthCheck( 9 | [ 10 | { user: "Tinky-Winky", sex: "male", age: 0 }, 11 | { user: "Dipsy", sex: "male", age: 3 }, 12 | { user: "Laa-Laa", sex: "female", age: 5 }, 13 | { user: "Po", sex: "female", age: 4 } 14 | ], 15 | "age" 16 | ) 17 | ); 18 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/19 argument optional/argumentoptional.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Create a function that sums two arguments together. If only one argument is provided, then return a function that expects one argument and returns the sum. 4 | 5 | For example, addTogether(2, 3) should return 5, and addTogether(2) should return a function. 6 | 7 | Calling this returned function with a single argument will then return the sum: 8 | 9 | var sumTwoAnd = addTogether(2); 10 | 11 | sumTwoAnd(3) returns 5. 12 | 13 | If either argument isn't a valid number, return undefined. -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/19 argument optional/index.js: -------------------------------------------------------------------------------- 1 | function addTogether() { 2 | var args = Array.from(arguments); 3 | return args.some(n => typeof n !== "number") 4 | ? undefined 5 | : args.length > 1 6 | ? args.reduce((acc, n) => (acc += n), 0) 7 | : n => (typeof n === "number" ? n + args[0] : undefined); 8 | } 9 | 10 | console.log(addTogether(2, 3)); 11 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/20 make a person/makeaperson.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Fill in the object constructor with the following methods below: 4 | 5 | getFirstName() getLastName() getFullName() setFirstName(first) setLastName(last) setFullName(firstAndLast) 6 | Run the tests to see the expected output for each method. 7 | 8 | The methods that take an argument must accept only one argument and it has to be a string. 9 | 10 | These methods must be the only available means of interacting with the object. -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/21 map and debris/mapanddebris.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Return a new array that transforms the elements' average altitude into their orbital periods (in seconds). 4 | 5 | The array will contain objects in the format {name: 'name', avgAlt: avgAlt}. 6 | 7 | You can read about orbital periods on Wikipedia. 8 | 9 | The values should be rounded to the nearest whole number. The body being orbited is Earth. 10 | 11 | The radius of the earth is 6367.4447 kilometers, and the GM value of earth is 398600.4418 km3s-2. 12 | 13 | -------------------------------------------------------------------------------- /Intermediate Algorithm Scripting/23 buying show tickets/index.js: -------------------------------------------------------------------------------- 1 | function waitingTime(tickets, p) { 2 | // Write your code here 3 | let time = tickets[p] 4 | let first = tickets.slice(0,p) 5 | let second = tickets.slice(p+1,tickets.length) 6 | console.log(first,second) 7 | 8 | for (let i of first) { 9 | console.log('i:',i) 10 | if (i < tickets[p]) { 11 | time += i 12 | } else { 13 | time += tickets[p] 14 | } 15 | } 16 | 17 | for (let j of second) { 18 | console.log('j;',j) 19 | if (j < tickets[p]) { 20 | time +=j 21 | } else { 22 | time += tickets[p] - 1 23 | } 24 | } 25 | 26 | return time; 27 | } 28 | 29 | waitingTime([2,6,3,4,5], 2) -------------------------------------------------------------------------------- /JavaScript Algorithms and Data Structures Projects/01 palindrome checker/index.js: -------------------------------------------------------------------------------- 1 | function palindrome(str) { 2 | str = str.toLowerCase().replace(/[\W_]/g, ""); 3 | for (let i = 0, letlen = str.length - 1; i < len / 2; i++) { 4 | if (str[i] !== str[len - i]) { 5 | return false; 6 | } 7 | } 8 | return true; 9 | } 10 | palindrome("eye"); 11 | -------------------------------------------------------------------------------- /JavaScript Algorithms and Data Structures Projects/01 palindrome checker/palindromechecker.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Return true if the given string is a palindrome. Otherwise, return false. 4 | 5 | A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing. 6 | 7 | Note 8 | You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes. 9 | 10 | We'll pass strings with varying formats, such as "racecar", "RaceCar", and "race CAR" among others. 11 | 12 | We'll also pass strings with special symbols, such as "2A3*3a2", "2A3 3a2", and "2_A3*3#A2". -------------------------------------------------------------------------------- /JavaScript Algorithms and Data Structures Projects/02 roman numeral converter/index.js: -------------------------------------------------------------------------------- 1 | let convertToRoman = function(num) { 2 | let decimalValue = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]; 3 | let romanNumeral = [ 4 | "M", 5 | "CM", 6 | "D", 7 | "CD", 8 | "C", 9 | "XC", 10 | "L", 11 | "XL", 12 | "X", 13 | "IX", 14 | "V", 15 | "IV", 16 | "I" 17 | ]; 18 | 19 | let romanized = ""; 20 | 21 | for (let index = 0; index < decimalValue.length; index++) { 22 | while (decimalValue[index] <= num) { 23 | romanized += romanNumeral[index]; 24 | num -= decimalValue[index]; 25 | } 26 | } 27 | 28 | return romanized; 29 | }; 30 | 31 | convertToRoman(36); 32 | -------------------------------------------------------------------------------- /JavaScript Algorithms and Data Structures Projects/02 roman numeral converter/romannumeralconverter.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | Convert the given number into a roman numeral. 4 | 5 | All roman numerals answers should be provided in upper-case. 6 | -------------------------------------------------------------------------------- /JavaScript Algorithms and Data Structures Projects/03 caesars cipher/caesarscipher.md: -------------------------------------------------------------------------------- 1 | :coffee: :fire: 2 | 3 | One of the simplest and most widely known ciphers is a Caesar cipher, also known as a shift cipher. In a shift cipher the meanings of the letters are shifted by some set amount. 4 | 5 | A common modern use is the ROT13 cipher, where the values of the letters are shifted by 13 places. Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on. 6 | 7 | Write a function which takes a ROT13 encoded string as input and returns a decoded string. 8 | 9 | All letters will be uppercase. Do not transform any non-alphabetic character (i.e. spaces, punctuation), but do pass them on. 10 | 11 | -------------------------------------------------------------------------------- /JavaScript Algorithms and Data Structures Projects/04 telephone number validator/index.js: -------------------------------------------------------------------------------- 1 | function telephoneCheck(str) { 2 | var regex = /^(1\s?)?(\(\d{3}\)|\d{3})[\s\-]?\d{3}[\s\-]?\d{4}$/; 3 | return regex.test(str); 4 | } 5 | telephoneCheck("555-555-5555"); 6 | -------------------------------------------------------------------------------- /Object Oriented Programming/01 create a basic Js object/index.js: -------------------------------------------------------------------------------- 1 | let dog = { 2 | name: "Jordan", 3 | numLegs: 4 4 | }; -------------------------------------------------------------------------------- /Object Oriented Programming/02 use dot notation to access the properties of an object/dotnotation.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The last challenge created an `object` with various properties, now you'll see how to access the values of those properties. Here's an example: 4 | 5 | ```js 6 | let duck = { 7 | name: "Aflac", 8 | numLegs: 2 9 | }; 10 | console.log(duck.name); 11 | // This prints "Aflac" to the console 12 | ``` 13 | 14 | Dot notation is used on the `object` name, `duck`, followed by the name of the `property`, `name`, to access the value of "Aflac". 15 | 16 | :fire: 17 | 18 | Print both `properties` of the `dog` object below to your console. 19 | -------------------------------------------------------------------------------- /Object Oriented Programming/02 use dot notation to access the properties of an object/index.js: -------------------------------------------------------------------------------- 1 | let dog = { 2 | name: "Spot", 3 | numLegs: 4 4 | }; 5 | // Add your code below this line 6 | 7 | console.log(dog.name); 8 | console.log(dog.numLegs); 9 | -------------------------------------------------------------------------------- /Object Oriented Programming/03 create a method on an object/index.js: -------------------------------------------------------------------------------- 1 | let dog = { 2 | name: "Spot", 3 | numLegs: 4, 4 | sayLegs: function() { 5 | return `This dog has ${dog.numLegs} legs.`; 6 | } 7 | }; 8 | 9 | dog.sayLegs(); 10 | -------------------------------------------------------------------------------- /Object Oriented Programming/04 make code more reusable with the this keyword/index.js: -------------------------------------------------------------------------------- 1 | let dog = { 2 | name: "Spot", 3 | numLegs: 4, 4 | sayLegs: function() {return "This dog has " + this.numLegs + " legs.";} 5 | }; 6 | 7 | dog.sayLegs(); -------------------------------------------------------------------------------- /Object Oriented Programming/05 define a constructor function/index.js: -------------------------------------------------------------------------------- 1 | function Dog() { 2 | this.name = "Jordan"; 3 | this.color = "Black & White"; 4 | this.numLegs = 4; 5 | } 6 | -------------------------------------------------------------------------------- /Object Oriented Programming/06 use a constructor to create objects/index.js: -------------------------------------------------------------------------------- 1 | function Dog() { 2 | this.name = "Rupert"; 3 | this.color = "brown"; 4 | this.numLegs = 4; 5 | } 6 | // Add your code below this line 7 | 8 | let hound = new Dog(); -------------------------------------------------------------------------------- /Object Oriented Programming/07 extend constructor to receive arguments/index.js: -------------------------------------------------------------------------------- 1 | function Dog(name, color) { 2 | this.name = name; 3 | this.color = color; 4 | this.numLegs = 4; 5 | } 6 | 7 | let terrier = new Dog("Jordan", "Black & White"); 8 | -------------------------------------------------------------------------------- /Object Oriented Programming/08 verify an object constructor with instanceof/index.js: -------------------------------------------------------------------------------- 1 | /* jshint expr: true */ 2 | 3 | function House(numBedrooms) { 4 | this.numBedrooms = numBedrooms; 5 | } 6 | 7 | // Add your code below this line 8 | 9 | 10 | let myHouse = new House(3); 11 | myHouse instanceof House; -------------------------------------------------------------------------------- /Object Oriented Programming/09 understand own properties/index.js: -------------------------------------------------------------------------------- 1 | function Bird(name) { 2 | this.name = name; 3 | this.numLegs = 2; 4 | } 5 | 6 | let canary = new Bird("Tweety"); 7 | let ownProps = []; 8 | // Add your code below this line 9 | 10 | 11 | for(let property in canary) { 12 | if(canary.hasOwnProperty(property)) { 13 | ownProps.push(property); 14 | } 15 | } 16 | 17 | console.log(ownProps); -------------------------------------------------------------------------------- /Object Oriented Programming/10 use prototype properties to reduce duplicate code/index.js: -------------------------------------------------------------------------------- 1 | function Dog(name) { 2 | this.name = name; 3 | } 4 | 5 | Dog.prototype.numLegs = 4; 6 | 7 | // Add your code above this line 8 | let beagle = new Dog("Snoopy"); 9 | 10 | -------------------------------------------------------------------------------- /Object Oriented Programming/11 iterate over all properties/index.js: -------------------------------------------------------------------------------- 1 | function Dog(name) { 2 | this.name = name; 3 | } 4 | 5 | Dog.prototype.numLegs = 4; 6 | 7 | let beagle = new Dog("Snoopy"); 8 | 9 | let ownProps = []; 10 | let prototypeProps = []; 11 | 12 | // Add your code below this line 13 | 14 | for (let property in beagle) { 15 | if (beagle.hasOwnProperty(property)) { 16 | ownProps.push(property); 17 | } else { 18 | prototypeProps.push(property); 19 | } 20 | } 21 | 22 | console.log(ownProps); 23 | console.log(prototypeProps); 24 | -------------------------------------------------------------------------------- /Object Oriented Programming/12 understand the constructor property/index.js: -------------------------------------------------------------------------------- 1 | function Dog(name) { 2 | this.name = name; 3 | } 4 | 5 | // Add your code below this line 6 | function joinDogFraternity(candidate) { 7 | if (candidate.constructor === Dog) { 8 | return true; 9 | } 10 | return false; 11 | } 12 | -------------------------------------------------------------------------------- /Object Oriented Programming/13 change the prototype to a new object/index.js: -------------------------------------------------------------------------------- 1 | function Dog(name) { 2 | this.name = name; 3 | } 4 | 5 | Dog.prototype = { 6 | // Add your code below this line 7 | numLegs: 4, 8 | eat: function() { 9 | console.log("woof woof"); 10 | }, 11 | describe: function() { 12 | console.log(`My name is ${this.name}`); 13 | } 14 | }; 15 | 16 | let tom = new Dog("Tom"); 17 | 18 | console.log(tom); 19 | console.log(tom.numLegs); 20 | console.log(tom.eat()); 21 | console.log(tom.describe()); 22 | -------------------------------------------------------------------------------- /Object Oriented Programming/14 remember to set the constructor property when changing the prototype/index.js: -------------------------------------------------------------------------------- 1 | function Dog(name) { 2 | this.name = name; 3 | } 4 | 5 | // Modify the code below this line 6 | Dog.prototype = { 7 | constructor: Dog, 8 | numLegs: 2, 9 | eat: function() { 10 | console.log("nom nom nom"); 11 | }, 12 | describe: function() { 13 | console.log("My name is " + this.name); 14 | } 15 | }; 16 | 17 | let dog = new Dog("Jordan"); 18 | console.log(dog.constructor()); 19 | console.log(dog.numLegs); 20 | console.log(dog.eat()); 21 | console.log(dog.describe()); 22 | console.log(dog.name); 23 | -------------------------------------------------------------------------------- /Object Oriented Programming/15 understand where an object prototype come from/index.js: -------------------------------------------------------------------------------- 1 | function Dog(name) { 2 | this.name = name; 3 | } 4 | 5 | let beagle = new Dog("Snoopy"); 6 | 7 | // Add your code below this line 8 | Dog.prototype.isPrototypeOf(beagle); 9 | -------------------------------------------------------------------------------- /Object Oriented Programming/15 understand where an object prototype come from/objectprototype.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Just like people inherit genes from their parents, an object inherits its `prototype` directly from the constructor function that created it. For example, here the Bird constructor creates the duck object: 4 | 5 | ```js 6 | function Bird(name) { 7 | this.name = name; 8 | } 9 | 10 | let duck = new Bird("Donald"); 11 | ``` 12 | 13 | `duck` inherits its `prototype` from the `Bird` constructor function. You can show this relationship with the `isPrototypeOf` method: 14 | 15 | ```js 16 | Bird.prototype.isPrototypeOf(duck); 17 | // returns true 18 | ``` 19 | 20 | :fire: 21 | 22 | Use `isPrototypeOf` to check the prototype of `beagle`. 23 | -------------------------------------------------------------------------------- /Object Oriented Programming/16 understand the prototype chain /index.js: -------------------------------------------------------------------------------- 1 | function Dog(name) { 2 | this.name = name; 3 | } 4 | 5 | let beagle = new Dog("Snoopy"); 6 | 7 | Dog.prototype.isPrototypeOf(beagle); // => true 8 | 9 | // Fix the code below so that it evaluates to true 10 | Object.prototype.isPrototypeOf(Dog.prototype); 11 | -------------------------------------------------------------------------------- /Object Oriented Programming/17 use inheritance so you don't repeat yourself/index.js: -------------------------------------------------------------------------------- 1 | function Cat(name) { 2 | this.name = name; 3 | } 4 | 5 | Cat.prototype = { 6 | constructor: Cat}; 7 | 8 | function Bear(name) { 9 | this.name = name; 10 | } 11 | 12 | Bear.prototype = { 13 | constructor: Bear 14 | }; 15 | 16 | function Animal() {} 17 | 18 | Animal.prototype = { 19 | constructor: Animal, 20 | eat: function() { 21 | console.log("nom nom nom"); 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /Object Oriented Programming/18 inherit behaviors from a supertype/index.js: -------------------------------------------------------------------------------- 1 | function Animal() { } 2 | 3 | Animal.prototype = { 4 | constructor: Animal, 5 | eat: function() { 6 | console.log("nom nom nom"); 7 | } 8 | }; 9 | 10 | // Add your code below this line 11 | 12 | let duck = Object.create(Animal.prototype); // Change this line 13 | let beagle = Object.create(Animal.prototype); // Change this line 14 | 15 | duck.eat(); // Should print "nom nom nom" 16 | beagle.eat(); // Should print "nom nom nom" -------------------------------------------------------------------------------- /Object Oriented Programming/19 set the child prototype to an instance of parent/index.js: -------------------------------------------------------------------------------- 1 | function Animal() { } 2 | 3 | Animal.prototype = { 4 | constructor: Animal, 5 | eat: function() { 6 | console.log("nom nom nom"); 7 | } 8 | }; 9 | 10 | function Dog() { } 11 | 12 | // Add your code below this line 13 | 14 | Dog.prototype = Object.create(Animal.prototype) 15 | let beagle = new Dog(); 16 | beagle.eat(); // Should print "nom nom nom" -------------------------------------------------------------------------------- /Object Oriented Programming/20 reset an inherited constructor property/index.js: -------------------------------------------------------------------------------- 1 | function Animal() { } 2 | function Bird() { } 3 | function Dog() { } 4 | 5 | Bird.prototype = Object.create(Animal.prototype); 6 | Dog.prototype = Object.create(Animal.prototype); 7 | 8 | // Add your code below this line 9 | Bird.prototype.constructor = Bird; 10 | Dog.prototype.constructor = Dog; 11 | 12 | 13 | let duck = new Bird(); 14 | let beagle = new Dog(); -------------------------------------------------------------------------------- /Object Oriented Programming/21 add methods after inheritance/index.js: -------------------------------------------------------------------------------- 1 | function Animal() {} 2 | Animal.prototype.eat = function() { 3 | console.log("nom nom nom"); 4 | }; 5 | 6 | function Dog() {} 7 | 8 | // Add your code below this line 9 | Dog.prototype = Object.create(Animal.prototype); 10 | Dog.prototype.constructor = Dog; 11 | 12 | Dog.prototype.eat = function() { 13 | console.log("nom nom nom"); 14 | } 15 | 16 | Dog.prototype.bark = function() { 17 | console.log("Woof!") 18 | } 19 | 20 | // Add your code above this line 21 | 22 | let beagle = new Dog(); 23 | 24 | beagle.eat(); // Should print "nom nom nom" 25 | beagle.bark(); // Should print "Woof!" 26 | -------------------------------------------------------------------------------- /Object Oriented Programming/22 ovveride inherited methods/index.js: -------------------------------------------------------------------------------- 1 | function Bird() {} 2 | 3 | Bird.prototype.fly = function() { 4 | return "I am flying!"; 5 | }; 6 | 7 | function Penguin() {} 8 | Penguin.prototype = Object.create(Bird.prototype); 9 | Penguin.prototype.constructor = Penguin; 10 | 11 | // Add your code below this line 12 | 13 | Penguin.prototype.fly = function() { 14 | return "Alas, this is a flightless bird."; 15 | }; 16 | 17 | // Add your code above this line 18 | 19 | let penguin = new Penguin(); 20 | console.log(penguin.fly()); 21 | -------------------------------------------------------------------------------- /Object Oriented Programming/23 use a mixin to add common behavior between unrelated objects/index.js: -------------------------------------------------------------------------------- 1 | let bird = { 2 | name: "Donald", 3 | numLegs: 2 4 | }; 5 | 6 | let boat = { 7 | name: "Warrior", 8 | type: "race-boat" 9 | }; 10 | 11 | // Add your code below this line 12 | 13 | let glideMixin = function(obj) { 14 | obj.glide = function() { 15 | console.log("gliding..."); 16 | }; 17 | }; 18 | glideMixin(bird); 19 | glideMixin(boat); 20 | 21 | bird.glide(); 22 | boat.glide(); 23 | -------------------------------------------------------------------------------- /Object Oriented Programming/24 use closure to protect properties within an object from being modified externally/index.js: -------------------------------------------------------------------------------- 1 | function Bird() { 2 | let weight = 15; 3 | 4 | this.getWeight = function() { 5 | return weight; 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /Object Oriented Programming/25 understand the immediately inoked function expression(iife)/iife.md: -------------------------------------------------------------------------------- 1 | :coffee: :star: 2 | 3 | A common pattern in JavaScript is to execute a function as soon as it is declared: 4 | ```js 5 | (function () { 6 | console.log("Chirp, chirp!"); 7 | })(); // this is an anonymous function expression that executes right away 8 | // Outputs "Chirp, chirp!" immediately 9 | ``` 10 | 11 | Note that the function has no name and is not stored in a variable. The two parentheses `()` at the end of the function expression cause it to be immediately executed or invoked. This pattern is known as an _immediately invoked function expression or IIFE._ 12 | 13 | :fire: 14 | 15 | Rewrite the function `makeNest` and remove its call so instead it's an anonymous immediately invoked function expression (IIFE). -------------------------------------------------------------------------------- /Object Oriented Programming/25 understand the immediately inoked function expression(iife)/index.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | console.log("A cozy nest is ready"); 3 | })(); 4 | -------------------------------------------------------------------------------- /Object Oriented Programming/26 use an iife to create a module/index.js: -------------------------------------------------------------------------------- 1 | let funModule = (function() { 2 | return { 3 | isCuteMixin: function(obj) { 4 | obj.isCute = function() { 5 | return true; 6 | }; 7 | }, 8 | singMixin: function(obj) { 9 | obj.sing = function() { 10 | console.log("Singing to an awesome tune"); 11 | }; 12 | } 13 | }; 14 | })(); 15 | -------------------------------------------------------------------------------- /Regular Expressions/01 using the test method/index.js: -------------------------------------------------------------------------------- 1 | let myString = "Hello, World!"; 2 | let myRegex = /Hello/; 3 | let result = myRegex.test(myString); // Change this line 4 | 5 | -------------------------------------------------------------------------------- /Regular Expressions/02 match literal strings/index.js: -------------------------------------------------------------------------------- 1 | let waldoIsHiding = "Somewhere Waldo is hiding in this text."; 2 | let waldoRegex = /Waldo/; // Change this line 3 | let result = waldoRegex.test(waldoIsHiding); -------------------------------------------------------------------------------- /Regular Expressions/03 match a literal string with different possibilites/index.js: -------------------------------------------------------------------------------- 1 | let petString = "James has a pet cat."; 2 | let petRegex = /cat|dog|bird|fish/; // Change this line 3 | let result = petRegex.test(petString); 4 | -------------------------------------------------------------------------------- /Regular Expressions/03 match a literal string with different possibilites/matchliteral.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Using regexes like `/coding/`, you can look for the pattern `"coding"` in another string. 4 | 5 | This is powerful to search single strings, but it's limited to only one pattern. You can search for multiple patterns using the `alternation` or `OR` operator: `|`. 6 | 7 | This operator matches patterns either before or after it. For example, if you wanted to match `"yes"` or `"no"`, the regex you want is /`yes|no/`. 8 | 9 | You can also search for more than just two patterns. You can do this by adding more patterns with more `OR` operators separating them, like `/yes|no|maybe/`. 10 | 11 | :fire: 12 | 13 | Complete the regex `petRegex` to match the pets `"dog"`, `"cat"`, `"bird"`, or `"fish"`. 14 | -------------------------------------------------------------------------------- /Regular Expressions/04 ignore case while matching/index.js: -------------------------------------------------------------------------------- 1 | let myString = "freeCodeCamp"; 2 | let fccRegex = /freecodecamp/i; // Change this line 3 | let result = fccRegex.test(myString); 4 | -------------------------------------------------------------------------------- /Regular Expressions/05 extract matches/extractmatches.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | So far, you have only been checking if a pattern exists or not within a string. You can also extract the actual matches you found with the `.match()` method. 4 | 5 | To use the `.match()` method, apply the method on a string and pass in the regex inside the parentheses. Here's an example: 6 | 7 | ```js 8 | "Hello, World!".match(/Hello/); 9 | // Returns ["Hello"] 10 | let ourStr = "Regular expressions"; 11 | let ourRegex = /expressions/; 12 | ourStr.match(ourRegex); 13 | // Returns ["expressions"] 14 | ``` 15 | 16 | :fire: 17 | 18 | Apply the `.match()` method to extract the word `coding`. 19 | -------------------------------------------------------------------------------- /Regular Expressions/05 extract matches/index.js: -------------------------------------------------------------------------------- 1 | let extractStr = "Extract the word 'coding' from this string."; 2 | let codingRegex = /coding/; // Change this line 3 | let result = extractStr.match(codingRegex); // Change this line 4 | -------------------------------------------------------------------------------- /Regular Expressions/06 find more than the first match/findmorematches.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | So far, you have only been able to extract or search a pattern once. 4 | 5 | ```js 6 | let testStr = "Repeat, Repeat, Repeat"; 7 | let ourRegex = /Repeat/; 8 | testStr.match(ourRegex); 9 | // Returns ["Repeat"] 10 | ``` 11 | 12 | To search or extract a pattern more than once, you can use the `g` flag. 13 | 14 | ```js 15 | let repeatRegex = /Repeat/g; 16 | testStr.match(repeatRegex); 17 | // Returns ["Repeat", "Repeat", "Repeat"] 18 | ``` 19 | 20 | :fire: 21 | 22 | Using the regex `starRegex`, find and extract both `"Twinkle"` words from the string twinkleStar. 23 | 24 | Note 25 | You can have multiple flags on your regex like /search/gi 26 | -------------------------------------------------------------------------------- /Regular Expressions/06 find more than the first match/index.js: -------------------------------------------------------------------------------- 1 | let twinkleStar = "Twinkle, twinkle, little star"; 2 | let starRegex = /twinkle/gi; // Change this line 3 | let result = twinkleStar.match(starRegex); // Change this line 4 | -------------------------------------------------------------------------------- /Regular Expressions/07 match anything with wildcard reriod/index.js: -------------------------------------------------------------------------------- 1 | let exampleStr = "Let's have fun with regular expressions!"; 2 | let unRegex = /.un/; // Change this line 3 | let result = unRegex.test(exampleStr); -------------------------------------------------------------------------------- /Regular Expressions/08 match signle character with multiple possobilites/index.js: -------------------------------------------------------------------------------- 1 | let quoteSample = 2 | "Beware of bugs in the above code; I have only proved it correct, not tried it."; 3 | let vowelRegex = /[aeiou]/gi; // Change this line 4 | let result = quoteSample.match(vowelRegex); // Change this line 5 | console.log(result.length); 6 | -------------------------------------------------------------------------------- /Regular Expressions/09 match letter of the alphabet/index.js: -------------------------------------------------------------------------------- 1 | let quoteSample = "The quick brown fox jumps over the lazy dog."; 2 | let alphabetRegex = /[a-z]/gi; // Change this line 3 | let result = quoteSample.match(alphabetRegex); // Change this line 4 | -------------------------------------------------------------------------------- /Regular Expressions/10 match numbers and letters of alphabet/index.js: -------------------------------------------------------------------------------- 1 | let quoteSample = "Blueberry 3.141592653s are delicious."; 2 | let myRegex = /[h-s2-6]/gi; // Change this line 3 | let result = quoteSample.match(myRegex); // Change this line 4 | -------------------------------------------------------------------------------- /Regular Expressions/10 match numbers and letters of alphabet/matchnumbers.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Using the hyphen (`-)` to match a range of characters is not limited to letters. It also works to match a range of numbers. 4 | 5 | For example, `/[0-5]/` matches any number between `0` and `5`, including the `0` and `5`. 6 | 7 | Also, it is possible to combine a range of letters and numbers in a single character set. 8 | 9 | ```js 10 | let jennyStr = "Jenny8675309"; 11 | let myRegex = /[a-z0-9]/gi; 12 | // matches all letters and numbers in jennyStr 13 | jennyStr.match(myRegex); 14 | ``` 15 | 16 | :fire: 17 | 18 | Create a single regex that matches a range of letters between `h` and `s`, and a range of numbers between `2` and `6`. Remember to include the appropriate flags in the regex. 19 | -------------------------------------------------------------------------------- /Regular Expressions/11 match single characters not specified/index.js: -------------------------------------------------------------------------------- 1 | let quoteSample = "3 blind mice."; 2 | let myRegex = /[^aeiou0-9]/gi; // Change this line 3 | let result = quoteSample.match(myRegex); // Change this line -------------------------------------------------------------------------------- /Regular Expressions/12 match characters that occure one or more times/index.js: -------------------------------------------------------------------------------- 1 | let difficultSpelling = "Mississippi"; 2 | let myRegex = /s+/g; // Change this line 3 | let result = difficultSpelling.match(myRegex); 4 | -------------------------------------------------------------------------------- /Regular Expressions/13 match characters that occur zero or more times/index.js: -------------------------------------------------------------------------------- 1 | let chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!"; 2 | let chewieRegex = /Aa*/g; // Change this line 3 | let result = chewieQuote.match(chewieRegex); 4 | console.log(result); 5 | -------------------------------------------------------------------------------- /Regular Expressions/14 find characters with lazy matching/index.js: -------------------------------------------------------------------------------- 1 | let text = "

Winter is coming

"; 2 | let myRegex = /

?/; // Change this line 3 | let result = text.match(myRegex); 4 | console.log(result); 5 | -------------------------------------------------------------------------------- /Regular Expressions/15 find one or more criminals in a hunt/index.js: -------------------------------------------------------------------------------- 1 | // example crowd gathering 2 | let crowd = 'P1P2P3P4P5P6CCCP7P8P9'; 3 | 4 | let reCriminals = /C+/gi; // Change this line 5 | 6 | let matchedCriminals = crowd.match(reCriminals); 7 | console.log(matchedCriminals); -------------------------------------------------------------------------------- /Regular Expressions/16 match beginning string patterns/index.js: -------------------------------------------------------------------------------- 1 | let rickyAndCal = "Cal and Ricky both like racing."; 2 | let calRegex = /^Cal/; // Change this line 3 | let result = calRegex.test(rickyAndCal); 4 | console.log(result); 5 | -------------------------------------------------------------------------------- /Regular Expressions/17 match ending string patterns/index.js: -------------------------------------------------------------------------------- 1 | let caboose = "The last car on a train is the caboose"; 2 | let lastRegex = /caboose$/; // Change this line 3 | let result = lastRegex.test(caboose); -------------------------------------------------------------------------------- /Regular Expressions/17 match ending string patterns/matchendingstring.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | In the last challenge, you learned to use the `caret` character to search for patterns at the beginning of strings. There is also a way to search for patterns at the end of strings. 4 | 5 | You can search the end of strings using the `dollar sign` character `$` at the end of the regex. 6 | 7 | ```js 8 | let theEnding = "This is a never ending story"; 9 | let storyRegex = /story$/; 10 | storyRegex.test(theEnding); 11 | // Returns true 12 | let noEnding = "Sometimes a story will have to end"; 13 | storyRegex.test(noEnding); 14 | // Returns false 15 | ``` 16 | 17 | :fire: 18 | 19 | Use the anchor character (`$`) to match the string `"caboose"` at the end of the string caboose. 20 | -------------------------------------------------------------------------------- /Regular Expressions/18 match all letters and numbers/index.js: -------------------------------------------------------------------------------- 1 | let quoteSample = "The five boxing wizards jump quickly."; 2 | let alphabetRegexV2 = /\w+/; // Change this line 3 | let result = quoteSample.match(alphabetRegexV2).length; -------------------------------------------------------------------------------- /Regular Expressions/19 match everything but letters and numbers/index.js: -------------------------------------------------------------------------------- 1 | let quoteSample = "The five boxing wizards jump quickly."; 2 | let nonAlphabetRegex = /\W/g; // Change this line 3 | let result = quoteSample.match(nonAlphabetRegex).length; 4 | console.log(result); 5 | -------------------------------------------------------------------------------- /Regular Expressions/19 match everything but letters and numbers/matcheverythingbutlettersandnumbers.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | You've learned that you can use a shortcut to match alphanumerics `[A-Za-z0-9_]` using `\w`. A natural pattern you might want to search for is the opposite of alphanumerics. 4 | 5 | You can search for the opposite of the `\w` with `\W`. Note, the opposite pattern uses a capital letter. This shortcut is the same as `[^A-Za-z0-9_]`. 6 | 7 | ```js 8 | let shortHand = /\W/; 9 | let numbers = "42%"; 10 | let sentence = "Coding!"; 11 | numbers.match(shortHand); // Returns ["%"] 12 | sentence.match(shortHand); // Returns ["!"] 13 | ``` 14 | 15 | :fire: 16 | 17 | Use the shorthand character class `\W` to count the number of non-alphanumeric characters in various quotes and strings. 18 | -------------------------------------------------------------------------------- /Regular Expressions/20 match all numbers/index.js: -------------------------------------------------------------------------------- 1 | let numString = "Your sandwich will be $5.00"; 2 | let numRegex = /\d/g; // Change this line 3 | let result = numString.match(numRegex).length; -------------------------------------------------------------------------------- /Regular Expressions/20 match all numbers/matchallnumbers.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | You've learned shortcuts for common string patterns like alphanumerics. Another common pattern is looking for just digits or numbers. 4 | 5 | The shortcut to look for digit characters is `\d`, with a lowercase `d`. This is equal to the character class `[0-9]`, which looks for a single character of any number between zero and nine. 6 | 7 | :fire: 8 | 9 | Use the shorthand character class `\d` to count how many digits are in movie titles. Written out numbers ("six" instead of 6) do not count. 10 | -------------------------------------------------------------------------------- /Regular Expressions/21 match all non numbers/index.js: -------------------------------------------------------------------------------- 1 | let numString = "Your sandwich will be $5.00"; 2 | let noNumRegex = /\D/g; // Change this line 3 | let result = numString.match(noNumRegex).length; -------------------------------------------------------------------------------- /Regular Expressions/21 match all non numbers/matchnonnumbers.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The last challenge showed how to search for digits using the shortcut `\d` with a lowercase `d`. You can also search for non-digits using a similar shortcut that uses an uppercase `D` instead. 4 | 5 | The shortcut to look for non-digit characters is `\D`. This is equal to the character class `[^0-9]`, which looks for a single character that is not a number between zero and nine. 6 | 7 | :fire: 8 | 9 | Use the shorthand character class for non-digits `\D` to count how many non-digits are in movie titles. 10 | -------------------------------------------------------------------------------- /Regular Expressions/22 restrict possible usernames/index.js: -------------------------------------------------------------------------------- 1 | let username = "JackOfAllTrades"; 2 | let userCheck = /^[a-z]{2,}\d*$/i; // Change this line 3 | let result = userCheck.test(username); -------------------------------------------------------------------------------- /Regular Expressions/22 restrict possible usernames/restrictusernames.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Usernames are used everywhere on the internet. They are what give users a unique identity on their favorite sites. 4 | 5 | You need to check all the usernames in a database. Here are some simple rules that users have to follow when creating their username. 6 | 7 | 1. The only numbers in the username have to be at the end. There can be zero or more of them at the end. 8 | 9 | 2. Username letters can be lowercase and uppercase. 10 | 11 | 3. Usernames have to be at least two characters long. A two-letter username can only use alphabet letter characters. 12 | 13 | :fire: 14 | 15 | Change the regex `userCheck` to fit the constraints listed above. 16 | -------------------------------------------------------------------------------- /Regular Expressions/23 match white spaces/index.js: -------------------------------------------------------------------------------- 1 | let sample = "Whitespace is important in separating words"; 2 | let countWhiteSpace = /\s/g; // Change this line 3 | let result = sample.match(countWhiteSpace); 4 | -------------------------------------------------------------------------------- /Regular Expressions/23 match white spaces/matchwhitespace.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | The challenges so far have covered matching letters of the alphabet and numbers. You can also match the whitespace or spaces between letters. 4 | 5 | You can search for whitespace using `\s`, which is a lowercase `s`. This pattern not only matches whitespace, but also carriage return, tab, form feed, and new line characters. You can think of it as similar to the character class `[ \r\t\f\n\v]`. 6 | 7 | ```js 8 | let whiteSpace = "Whitespace. Whitespace everywhere!"; 9 | let spaceRegex = /\s/g; 10 | whiteSpace.match(spaceRegex); 11 | // Returns [" ", " "] 12 | ``` 13 | 14 | :fire: 15 | 16 | Change the regex `countWhiteSpace` to look for multiple whitespace characters in a string. 17 | -------------------------------------------------------------------------------- /Regular Expressions/24 match non whitespace characters/index.js: -------------------------------------------------------------------------------- 1 | let sample = "Whitespace is important in separating words"; 2 | let countNonWhiteSpace = /\S/g; // Change this line 3 | let result = sample.match(countNonWhiteSpace); -------------------------------------------------------------------------------- /Regular Expressions/24 match non whitespace characters/matchnonspace.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | You learned about searching for whitespace using `\s`, with a lowercase `s`. You can also search for everything except whitespace. 4 | 5 | Search for non-whitespace using `\S`, which is an uppercase `s`. This pattern will not match whitespace, carriage return, tab, form feed, and new line characters. You can think of it being similar to the character class `[^ \r\t\f\n\v]`. 6 | 7 | ```js 8 | let whiteSpace = "Whitespace. Whitespace everywhere!"; 9 | let nonSpaceRegex = /\S/g; 10 | whiteSpace.match(nonSpaceRegex).length; // Returns 32 11 | ``` 12 | 13 | :fire: 14 | 15 | Change the regex countNonWhiteSpace to look for multiple non-whitespace characters in a string. 16 | -------------------------------------------------------------------------------- /Regular Expressions/25 specify upper and lower number of matches/index.js: -------------------------------------------------------------------------------- 1 | let ohStr = "Ohhh no"; 2 | let ohRegex = /Oh{3,5}\sno/; // Change this line 3 | let result = ohRegex.test(ohStr); 4 | console.log(result); 5 | -------------------------------------------------------------------------------- /Regular Expressions/26 specify only the lower number of matches/index.js: -------------------------------------------------------------------------------- 1 | let haStr = "Hazzzzah"; 2 | let haRegex = /Haz{4,}ah/; // Change this line 3 | let result = haRegex.test(haStr); 4 | -------------------------------------------------------------------------------- /Regular Expressions/27 specify exact number of matches/index.js: -------------------------------------------------------------------------------- 1 | let timStr = "Timmmmber"; 2 | let timRegex = /Tim{4}ber/; // Change this line 3 | let result = timRegex.test(timStr); -------------------------------------------------------------------------------- /Regular Expressions/28 check for all or none/index.js: -------------------------------------------------------------------------------- 1 | let favWord = "favorite"; 2 | let favRegex = /favou?rite/; // Change this line 3 | let result = favRegex.test(favWord); -------------------------------------------------------------------------------- /Regular Expressions/29 positive ans negative looahead/index.js: -------------------------------------------------------------------------------- 1 | let sampleWord = "astronaut"; 2 | let pwRegex = /(?=\w{5,})(?=\D*\d{2})/; // Change this line 3 | let result = pwRegex.test(sampleWord); -------------------------------------------------------------------------------- /Regular Expressions/30 reuse patterns using capture groups/index.js: -------------------------------------------------------------------------------- 1 | let repeatNum = "42 42 42"; 2 | let reRegex = /^(\d+)\s\1\s\1$/; // Change this line 3 | let result = reRegex.test(repeatNum); -------------------------------------------------------------------------------- /Regular Expressions/31 use capture groups to search and replace/index.js: -------------------------------------------------------------------------------- 1 | let huhText = "This sandwich is good."; 2 | let fixRegex = /good/; // Change this line 3 | let replaceText = "okey-dokey"; // Change this line 4 | let result = huhText.replace(fixRegex, replaceText); -------------------------------------------------------------------------------- /Regular Expressions/32 remove whitespce from start and end/index.js: -------------------------------------------------------------------------------- 1 | let hello = " Hello, World! "; 2 | let wsRegex = /^\s+|\s+$/g; // Change this line 3 | let result = hello.replace(wsRegex, ""); // Change this line -------------------------------------------------------------------------------- /Regular Expressions/32 remove whitespce from start and end/removewhitespace.md: -------------------------------------------------------------------------------- 1 | :coffee: 2 | 3 | Sometimes whitespace characters around strings are not wanted but are there. Typical processing of strings is to remove the whitespace at the start and end of it. 4 | 5 | :fire: 6 | 7 | Write a regex and use the appropriate string methods to remove whitespace at the beginning and end of strings. 8 | 9 | Note 10 | The `.trim()` method would work here, but you'll need to complete this challenge using regular expressions. --------------------------------------------------------------------------------