├── 02_ES6 ├── README.md ├── index.html └── 01_compare_scopes_of_the_var_and_let_keywords.js ├── 01_Basic_JavaScript ├── 040_nest_one_array_within_another.js ├── 097_iterate_with_javaScript_for_loops.js ├── 099_count_backwards_with_a_for_loop.js ├── 106_generate_random_whole_numbers_with_javaScript.js ├── 014_divide_one_number_by_another_with_javascript.js ├── 019_divide_one_decimal_by_another_with_javaScript.js ├── 012_substract_one_number_from_another_with_javaScript.js ├── 013_multiply_two_numbers_with_javaScript.js ├── 096_iterate_with_javaScript_while_loops.js ├── 098_iterate_odd_numbers_with_a_for_loop.js ├── 103_replace_loops_using_recursion.js ├── 039_store_multiple_values_in_one_variable_using_javaScript_arrays.js ├── 011_add_two_numbers_with_javaScript.js ├── 018_multiply_two_decimals_with_javaScript.js ├── 042_modify_array_data_with_indexes.js ├── 108_use_the_parse_int_function.js ├── 015_increment_a_number_with_javaScript.js ├── 020_finding_a_remainder_in_javaScript.js ├── 100_iterate_through_an_array_with_a_for_loop.js ├── 016_decrement_a_number_with_javaScript.js ├── 089_delete_properties_from_a_javaScript_object.js ├── 049_functions.js ├── 005_initializing_variables_with_assignment_operator.js ├── 111_use_multiple_conditional_operators.js ├── 009_let_var_keywords.js ├── 107_generate_random_whole_numbers_within_a_range.js ├── 051_return_a_value_from_a_function_with_return.js ├── 056_assignment_with_a_returned_value.js ├── 102_iterate_with_javaScript_do_while_loops.js ├── 006_declare_string_variables.js ├── 022_compound_assignment_with_augmented_subtraction.js ├── 047_manipulate_arrays_with_unshift.js ├── 044_manipulate_arrays_with_push.js ├── 024_compound_assignment_with_augmented_division.js ├── 028_concatenating_strings_with_plus_operator.js ├── 101_nesting_loops.js ├── 003_storing_values_with_assignment_operator.js ├── 050_passing_values_to_functions_with_arguments.js ├── 058_understanding_boolean_values.js ├── 072_introducing_else_if_statements.js ├── 109_une_the_parseInt_function_with_a_radix.js ├── 023_compound_assignment_with_augmented_multiplication.js ├── 025_escaping_literal_quotes_in_strings.js ├── 105_generate_random_functions_with_javaScript.js ├── 080_returning_boolean_values_from_functions.js ├── 030_constructing_strings_with_variables.js ├── 054_local_global_scope_with_functions.js ├── 017_create_decimal_number_with_javaScript.js ├── 021_compound_assignment_with_augmented_addition.js ├── 060_comparison_with_the_equality_operator.js ├── 008_case_sensitivity_in_variables.js ├── 034_understanding_string_immutability.js ├── 088_add_new_properties_to_javaScript_object.js ├── 037_use_bracket_notation_to_find_the_nth_to_last_character_in_a_string.js ├── 031_appending_variables_to_string.js ├── 048_shopping_list.js ├── 094_accessing_nested_arrays.js ├── 071_introducing_else_statement.js ├── 087_updating_object_properties.js ├── 073_logical_order_in_if_else_statements.js ├── 081_return_early_pattern_for_functions.js ├── 036_use_bracket_notation_to_find_the_last_character_in_a_string.js ├── 032_find_length_of_a_string.js ├── 002_declare_javascript_variables.js ├── 035_use_bracket_notation_to_find_the_nth_character_in_a_string.js ├── 046_manipulate_arrays_with_shift.js ├── 055_understanding_undefined_value_returned_from_a_function.js ├── 083_build_javaScript_objects.js ├── 041_access_array_data_with_indexes.js ├── 069_comparisons_with_the_logical_and_operator.js ├── 086_accessing_object_properties_with_variables.js ├── 110_use_the_conditional_operator.js ├── 063_comparison_with_the_inequality_operator.js ├── 092_manipulating_complex_objects.js ├── 064_comparison_with_the_strict_inequality_operator.js ├── 043_access_multi_dimensional_array_with_indexes.js ├── 070_comparisons_with_the_logical_or_operator.js ├── 067_comparison_with_the_less_than_operator.js ├── 033_use_brack_notation_to_find_the_first_character_in_a_string.js ├── 084_accessing_object_properties_with_dot_notation.js ├── 045_manipulate_array_with_pop.js ├── 065_comparison_with_the_grater_than_operator.js ├── 062_practice_comparing_different_values.js ├── 093_accessing_nested_objects.js ├── 091_testing_objects_for_properties.js ├── 007_uninitialized_variables.js ├── 061_comparison_with_the_strict_equality_operator.js ├── 053_local_scope_and_functions.js ├── 004_assigning_the_value_of_one_variable_to_another.js ├── 074_chaining_if_else_statements.js ├── 029_concatenating_strings_with_the_plus_equals_operator.js ├── 026_quoting_strings_with_single_quotes.js ├── 066_comparison_with_the_grater_than_or_equal_to_operator.js ├── 085_accessing_object_properties_with_bracket_notation.js ├── 068_comparison_with_the_less_than_or_equal_to_operator.js ├── 038_word_blanks.js ├── 010_read_only_variable_const_keyword.js ├── 113_use_recursion_to_create_a_range_numbers.js ├── 001_comment_your_javascript_code.js ├── 057_stand_in_line.js ├── 027_escape_sequences_in_strings.js ├── 059_use_conditional_logic_with_if_statement.js ├── 077_adding_default_option_in_switch_statement.js ├── 076_selecting_from_many_options_with_switch_statements.js ├── 078_multiple_identical_options_in_switch_statements.js ├── 052_global_scope_and_functions.js ├── 112_use _recursion_to_create_a_countdown.js ├── 079_replacing_if_else_chains_with_switch.js ├── 075_golf_code.js ├── 090_using_objects_for_lookups.js ├── 082_counting_cards.js ├── 104_profile_lookup.js ├── 095_record_collection.js ├── index.html └── README.md └── README.md /02_ES6/README.md: -------------------------------------------------------------------------------- 1 | ### ES6 :heavy_check_mark: 2 | * [x] [Compare Scopes of the var and let Keywords](https://github.com/somekindofwallflower/javascript-algorithms-and-data-structures/tree/master/02_ES6/01_compare_scopes_of_the_var_and_let_keywords.js) 3 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/040_nest_one_array_within_another.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // When you nest an array inside another it is called multi-dimensional array. 4 | 5 | // Task: Create a nested array called myArray. 6 | 7 | const myArray = [["Bulls", 23], ["White Sox", 45]]; 8 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/097_iterate_with_javaScript_for_loops.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Task: Use a for loop to push the values 1 through 5 onto myArray. 4 | 5 | const myArray = []; 6 | 7 | for(let i = 1; i <= 5; i++) { 8 | myArray.push(i); 9 | } 10 | 11 | console.log(myArray); 12 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/099_count_backwards_with_a_for_loop.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Task: Push the odd numbers from 9 through 1 to myArray using a for loop. 4 | 5 | const myArray = []; 6 | 7 | for(let i = 9; i >= 1; i--) { 8 | myArray.push(i); 9 | } 10 | 11 | console.log(myArray); 12 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/106_generate_random_whole_numbers_with_javaScript.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Task: Generate and return a random whole number between 0 and 9. 4 | 5 | function randomWholeNum() { 6 | return Math.floor(Math.random() * 10); 7 | } 8 | 9 | console.log(randomWholeNum()); 10 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/014_divide_one_number_by_another_with_javascript.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // JavaScript uses the / symbol for division. 4 | 5 | /*Task: Change the 0 so that the quotient is equal to 2. 6 | const quotient = 66 / 0;*/ 7 | 8 | const quotient = 66 / 33; 9 | console.log(quotient); 10 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/019_divide_one_decimal_by_another_with_javaScript.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | Task: Change the 0.0 so that quotient will equal to 2.2. 5 | const quotient = 0.0 / 2.0; // Change this line 6 | */ 7 | 8 | const quotient = 4.4 / 2.0; 9 | console.log("Quotient", quotient) 10 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/012_substract_one_number_from_another_with_javaScript.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // JavaScript uses the - symbol for subtraction. 4 | 5 | /* 6 | Task: Change the 0 so the difference is 12. 7 | const difference = 45 - 0;*/ 8 | 9 | const difference = 45 - 33; 10 | console.log(difference); 11 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/013_multiply_two_numbers_with_javaScript.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // JavaScript uses the * symbol for multiplication of two numbers. 4 | 5 | /* 6 | Task: Change the 0 so that product will equal 80. 7 | const product = 8 * 0;*/ 8 | 9 | const product = 8 * 10; 10 | console.log(product); 11 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/096_iterate_with_javaScript_while_loops.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Task: Add the numbers 5 through 0 (inclusive) in descending order to myArray using a while loop. 4 | 5 | const myArray = []; 6 | let i = 5; 7 | 8 | while (i <= 5 && i >= 0) { 9 | myArray.push(i); 10 | i--; 11 | } 12 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/098_iterate_odd_numbers_with_a_for_loop.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Task: Push the odd numbers from 1 through 9 to myArray using a for loop. 4 | 5 | const myArray = []; 6 | 7 | for (let i = 1; i <= 9; i++) { 8 | if(i % 2 != 0) { 9 | myArray.push(i); 10 | } 11 | } 12 | 13 | console.log(myArray); 14 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/103_replace_loops_using_recursion.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Task: Write a recursive function, sum(arr, n), that returns the sum of the first n elements of an array arr. 4 | function sum(arr, n) { 5 | if (n <= 0) { 6 | return 0; 7 | } else { 8 | return sum(arr, n - 1) + arr[n - 1]; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/039_store_multiple_values_in_one_variable_using_javaScript_arrays.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // With JavaScript array variables, we can store several pieces of data in one place. 4 | 5 | // Task: Modify the new array myArray so that it contains both a string and a number (in that order). 6 | 7 | const myArray = ["test", 13]; 8 | console.log("My array: ", myArray); 9 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/011_add_two_numbers_with_javaScript.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Number is a data type in JavaScript which represents numeric data. 4 | // JavaScript uses the + symbol as an addition operator when placed between two numbers. 5 | 6 | /*Task: Change the 0 so that sum will equal 20. 7 | const sum = 10 + 0;*/ 8 | 9 | const sum = 10 + 10; 10 | console.log(sum); 11 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/018_multiply_two_decimals_with_javaScript.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // In JavaScript, you can also perform calculations with decimal numbers, just like whole numbers. 4 | 5 | /* 6 | Task: Change the 0.0 so that product will equal 5.0. 7 | 8 | const product = 2.0 * 0.0; 9 | 10 | */ 11 | 12 | const product = 2.0 * 2.5; 13 | console.log("Product", product); 14 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/042_modify_array_data_with_indexes.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Unlike strings, the entries of arrays are mutable and can be changed freely, even if the array was declared with const. 4 | 5 | // Task: Modify the data stored at index 0 of myArray to a value of 45. 6 | 7 | const myArray = [18, 64, 99]; 8 | myArray[0] = 45; 9 | console.log("Updated array", myArray); 10 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/108_use_the_parse_int_function.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // The parseInt() function parses a string and returns an integer. 4 | 5 | // Task: Use parseInt() in the convertToInteger function so it converts the input string str into an integer, and returns it. 6 | 7 | function convertToInteger(str) { 8 | return parseInt(str); 9 | } 10 | 11 | convertToInteger("56"); 12 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/015_increment_a_number_with_javaScript.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Easily increment or add one to a variable with the ++ operator. 4 | 5 | /* 6 | Task: Change the code to use the ++ operator on myVar. 7 | 8 | let myVar = 87; 9 | // Only change code below this line 10 | myVar = myVar + 1; 11 | 12 | */ 13 | 14 | let myVar = 87; 15 | myVar++; 16 | console.log(myVar); 17 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/020_finding_a_remainder_in_javaScript.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // The remainder operator % gives the remainder of the division of two numbers. 4 | 5 | /* 6 | Task: Set remainder equal to the remainder of 11 divided by 3 using the remainder (%) operator. 7 | 8 | const remainder = 0; 9 | */ 10 | 11 | const remainder = 11 % 3; 12 | console.log("Remainder", remainder); 13 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/100_iterate_through_an_array_with_a_for_loop.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Task: 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. 4 | 5 | const myArr = [2, 3, 4, 5, 6]; 6 | 7 | let total = 0; 8 | for (let i = 0; i < myArr.length; i++) { 9 | total += myArr[i]; 10 | } 11 | 12 | console.log(total); 13 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/016_decrement_a_number_with_javaScript.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Easily decrement or decrease a variable by one with the -- operator. 4 | 5 | /* 6 | Task: Change the code to use the -- operator on myVar. 7 | 8 | let myVar = 11; 9 | // Only change code below this line 10 | myVar = myVar - 1; 11 | 12 | */ 13 | 14 | 15 | let myVar = 11; 16 | myVar--; 17 | console.log(myVar); 18 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/089_delete_properties_from_a_javaScript_object.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Task: Delete the tails property from myDog. You may use either dot or bracket notation. 4 | 5 | // Setup 6 | const myDog = { 7 | "name": "Happy Coder", 8 | "legs": 4, 9 | "tails": 1, 10 | "friends": ["freeCodeCamp Campers"], 11 | "bark": "woof" 12 | }; 13 | 14 | delete myDog.tails; 15 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/049_functions.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // In JavaScript, we can divide up our code into reusable parts called functions. 4 | 5 | /*Task: 6 | 1) Create a function called reusableFunction which prints the string Hi World to the dev console. 7 | 2) Call the function.*/ 8 | 9 | function reusableFunction () { 10 | console.log("Hi World"); 11 | } 12 | 13 | reusableFunction(); 14 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/005_initializing_variables_with_assignment_operator.js: -------------------------------------------------------------------------------- 1 | // Initializing Variables with the Assignment Operator 2 | 3 | /* 4 | It is common to initialize a variable to an initial value in the same line as it is declared. 5 | var myVar = 0; 6 | Creates a new variable called myVar and assigns it an initial value of 0.*/ 7 | 8 | // Task: Define a variable a with var and initialize it to a value of 9./ 9 | var a = 9; 10 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/111_use_multiple_conditional_operators.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Task: In the checkSign function, use multiple conditional operators - following the recommended format used in findGreaterOrEqual - to check if a number is positive, negative or zero. The function should return positive, negative or zero. 4 | function checkSign(num) { 5 | return num < 0 ? "negative" : (num > 0 ? "positive" : "zero") 6 | } 7 | 8 | checkSign(10); 9 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/009_let_var_keywords.js: -------------------------------------------------------------------------------- 1 | // Differences Between the var and let Keywords 2 | 3 | // Declared variables with the var keyword can easily be overwritten 4 | // So unlike var, when you use let, a variable with the same name can only be declared once. 5 | 6 | // Update the code, so it only uses the let keyword. 7 | // var catName = "Oliver"; 8 | // var catSound = "Meow!"; 9 | 10 | let catName = "Oliver"; 11 | let catSound = "Meow!"; 12 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/107_generate_random_whole_numbers_within_a_range.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Create a function called randomRange that takes a range myMin and myMax and returns a random whole number that's greater than or equal to myMin, and is less than or equal to myMax, inclusive. 4 | 5 | function randomRange(myMin, myMax) { 6 | return Math.floor(Math.random() * (myMax - myMin + 1)) + myMin 7 | } 8 | 9 | console.log(randomRange(7, 15)); 10 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/051_return_a_value_from_a_function_with_return.js: -------------------------------------------------------------------------------- 1 | "use strict"; 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 | // Task: Create a function timesFive that accepts one argument, multiplies it by 5, and returns the new value. 6 | 7 | function timesFive(arg) { 8 | return 5 * arg; 9 | } 10 | 11 | timesFive(5); 12 | console.log("Result: ", timesFive(5)); 13 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/056_assignment_with_a_returned_value.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // We can take the return value of a function and assign it to a variable. 4 | 5 | // Task: Call the processArg function with an argument of 7 and assign its return value to the variable processed. 6 | 7 | // Setup 8 | let processed = 0; 9 | 10 | function processArg(num) { 11 | return (num + 3) / 5; 12 | } 13 | 14 | processed = processArg(7); 15 | console.log("Processed", processed); 16 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/102_iterate_with_javaScript_do_while_loops.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Task: Change the while loop in the code to a do...while loop so the loop will push only the number 10 to myArray, and i will be equal to 11 when your code has finished running. 4 | 5 | // Setup 6 | const myArray = []; 7 | let i = 10; 8 | 9 | // Only change code below this line 10 | do { 11 | myArray.push(i); 12 | } 13 | while (i < 5) { 14 | i++; 15 | } 16 | 17 | console.log(myArray) 18 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/006_declare_string_variables.js: -------------------------------------------------------------------------------- 1 | /* 2 | Declare String Variables 3 | var myName = "your name"; 4 | "your name" is called a string literal. A string literal, or string, is a series of zero or more characters enclosed in single or double quotes.*/ 5 | 6 | // Task: Create two new string variables: myFirstName and myLastName and assign them the values of your first and last name, respectively. 7 | 8 | var myFirstName = "Some Kind of"; 9 | var myLastName = "Wallflower"; 10 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/022_compound_assignment_with_augmented_subtraction.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // -= operator subtracts a number from a variable. 4 | /* 5 | 6 | Task: Convert the assignments for a, b, and c to use the -= operator. 7 | 8 | let a = 11; 9 | let b = 9; 10 | let c = 3; 11 | 12 | // Only change code below this line 13 | a = a - 6; 14 | b = b - 15; 15 | c = c - 1; 16 | 17 | */ 18 | 19 | let a = 11; 20 | let b = 9; 21 | let c = 3; 22 | a -= 6; 23 | b -= 15; 24 | c -= 1; 25 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/047_manipulate_arrays_with_unshift.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // .unshift() works exactly like .push(), but instead of adding the element at the end of the array, unshift() adds the element at the beginning of the array. 4 | 5 | // Task: Add ["Paul", 35] to the beginning of the myArray variable using unshift(). 6 | 7 | // Setup 8 | const myArray = [["John", 23], ["dog", 3]]; 9 | myArray.shift(); 10 | myArray.unshift(["Paul", 35]); 11 | console.log("My array: ", myArray); 12 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/044_manipulate_arrays_with_push.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // An easy way to append data to the end of an array is via the push() function. 4 | // .push() takes one or more parameters and "pushes" them onto the end of the array. 5 | 6 | // Task: Push ["dog", 3] onto the end of the myArray variable. 7 | 8 | 9 | // Setup 10 | const myArray = [["John", 23], ["cat", 2]]; 11 | // Only change code below this line 12 | myArray.push(["dog", 3]); 13 | console.log("My array: ", myArray); 14 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/024_compound_assignment_with_augmented_division.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // The /= operator divides a variable by another number. 4 | 5 | /* 6 | Task: Convert the assignments for a, b, and c to use the /= operator. 7 | 8 | let a = 48; 9 | let b = 108; 10 | let c = 33; 11 | 12 | // Only change code below this line 13 | a = a / 12; 14 | b = b / 4; 15 | c = c / 11; 16 | 17 | */ 18 | 19 | let a = 48; 20 | let b = 108; 21 | let c = 33; 22 | 23 | a /= 12; 24 | b /= 4; 25 | c /= 11; 26 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/028_concatenating_strings_with_plus_operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // In JavaScript, when the + operator is used with a String value, it is called the concatenation operator. 4 | // You can build a new string out of other strings by concatenating them together. 5 | 6 | // Task: Build myStr from the strings This is the start. and This is the end. using the + operator. Be sure to include a space between the two strings. 7 | 8 | const myStr = "This is the start." + " " + "This is the end."; 9 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/101_nesting_loops.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Task: Modify function multiplyAll so that it returns the product of all the numbers in the sub-arrays of arr. 4 | 5 | function multiplyAll(arr) { 6 | let product = 1; 7 | for(let i = 0; i < arr.length; i++) { 8 | for(let j = 0; j < arr[i].length; j++) { 9 | product *= arr[i][j]; 10 | } 11 | } 12 | return product; 13 | } 14 | 15 | multiplyAll([[1, 2], [3, 4], [5, 6, 7]]); 16 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/003_storing_values_with_assignment_operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Storing Values with the Assignment Operator 4 | 5 | // In JavaScript, you can store a value in a variable with the assignment operator (=). 6 | 7 | /* First, this code creates a variable named myVar. 8 | Then, the code assigns 5 to myVar. Now, if myVar appears again in the code, the program will treat it as if it is 5. 9 | var myVar; 10 | myVar = 5; */ 11 | 12 | // Task: Assign the value 7 to variable a. 13 | 14 | var a = 7; 15 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/050_passing_values_to_functions_with_arguments.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Parameters are variables that act as placeholders for the values that are to be input to a function when it is called 4 | 5 | /* 6 | Task: 1) Create a function called functionWithArgs that accepts two arguments and outputs their sum to the dev console. 7 | 2) Call the function with two numbers as arguments.*/ 8 | 9 | function functionWithArgs(arg1, arg2) { 10 | console.log(arg1 + arg2) 11 | } 12 | 13 | functionWithArgs(2, 3); 14 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/058_understanding_boolean_values.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // 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. 4 | 5 | // Task: Modify the welcomeToBooleans function so that it returns true instead of false when the run button is clicked. 6 | 7 | 8 | function welcomeToBooleans() { 9 | // return false; 10 | return true; 11 | } 12 | 13 | console.log("Welcome to boolean return function value is: ", welcomeToBooleans()); 14 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/072_introducing_else_if_statements.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // If you have multiple conditions that need to be addressed, you can chain if statements together with else if statements. 4 | 5 | 6 | // Task: Convert the logic to use else if statements. 7 | 8 | function testElseIf(val) { 9 | if (val > 10) { 10 | return "Greater than 10"; 11 | } else if (val < 5) { 12 | return "Smaller than 5"; 13 | } else { 14 | return "Between 5 and 10"; 15 | } 16 | } 17 | 18 | testElseIf(7); 19 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/109_une_the_parseInt_function_with_a_radix.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // The parseInt() function parses a string and returns an integer. 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 | // Task: Use parseInt() in the convertToInteger function so it converts a binary number to an integer and returns it. 6 | 7 | function convertToInteger(str) { 8 | return parseInt(str, 2); 9 | } 10 | 11 | convertToInteger("10011"); 12 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/023_compound_assignment_with_augmented_multiplication.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // The *= operator multiplies a variable by a number. 4 | 5 | /* 6 | Task: Convert the assignments for a, b, and c to use the *= operator. 7 | 8 | let a = 5; 9 | let b = 12; 10 | let c = 4.6; 11 | 12 | // Only change code below this line 13 | a = a * 5; 14 | b = 3 * b; 15 | c = c * 10; 16 | 17 | */ 18 | 19 | let a = 5; 20 | let b = 12; 21 | let c = 4.6; 22 | 23 | // Only change code below this line 24 | a *= 5; 25 | b *= 3; 26 | c *= 10; 27 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/025_escaping_literal_quotes_in_strings.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // In JavaScript, you can escape a quote from considering it as an end of string quote by placing a backslash (\) in front of the quote. 4 | 5 | /* 6 | Task: Use backslashes to assign a string to the myStr variable so that if you were to print it to the console, you would see: 7 | I am a "double quoted" string inside "double quotes".*/ 8 | 9 | const myStr = "I am a \"double quoted\" string inside \"double quotes\"."; 10 | console.log("String", myStr); 11 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/105_generate_random_functions_with_javaScript.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | Random numbers are useful for creating random behavior. 5 | JavaScript has a Math.random() function that generates a random decimal number between 0 (inclusive) and 1 (exclusive). 6 | Thus Math.random() can return a 0 but never return a 1.*/ 7 | 8 | // Task : Change randomFraction to return a random number instead of returning 0. 9 | 10 | function randomFraction() { 11 | return Math.random(); 12 | } 13 | 14 | console.log(randomFraction()); 15 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/080_returning_boolean_values_from_functions.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | Task: Fix the function isLess to remove the if/else statements. 5 | 6 | function isLess(a, b) { 7 | // Only change code below this line 8 | if (a < b) { 9 | return true; 10 | } else { 11 | return false; 12 | } 13 | // Only change code above this line 14 | } 15 | 16 | isLess(10, 15);*/ 17 | 18 | 19 | function isLess(a, b) { 20 | return a < b; 21 | } 22 | 23 | isLess(10, 15); 24 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/030_constructing_strings_with_variables.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // By using the concatenation operator (+), you can insert one or more variables into a string you're building. 4 | 5 | /* 6 | Task: 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! 7 | 8 | const myName = ""; 9 | const myStr = ""; 10 | 11 | */ 12 | 13 | const myName = "Some kind of Wallflower"; 14 | const myStr = "My name is" + myName + "and I am well!"; 15 | 16 | console.log("My string", myStr); 17 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/054_local_global_scope_with_functions.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // It is possible to have both local and global variables with the same name. When you do this, the local variable takes precedence over the global variable. 4 | 5 | // Task: Add a local variable to myOutfit function to override the value of outerWear with the string sweater. 6 | 7 | // Setup 8 | const outerWear = "T-Shirt"; 9 | 10 | function myOutfit() { 11 | const outerWear = "sweater" 12 | return outerWear; 13 | } 14 | 15 | console.log("Result", myOutfit()); 16 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/017_create_decimal_number_with_javaScript.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // We can store decimal numbers in variables too. Decimal numbers are sometimes referred to as floating point numbers or floats. 4 | 5 | /*Task: Create a variable myDecimal and give it a decimal value with a fractional part (e.g. 5.7). 6 | 7 | const ourDecimal = 5.7; 8 | // Only change code below this line 9 | 10 | */ 11 | 12 | const ourDecimal = 5.7; 13 | const myDecimal = 13.27; 14 | 15 | console.log("Our Decimal", ourDecimal); 16 | console.log("My Decimal", myDecimal); 17 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/021_compound_assignment_with_augmented_addition.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Operators can do both a mathematical operation and assignment in one step. 4 | // One such operator is the += operator. 5 | 6 | /* 7 | Task: Convert the assignments for a, b, and c to use the += operator. 8 | 9 | let a = 3; 10 | let b = 17; 11 | let c = 12; 12 | 13 | // Only change code below this line 14 | a = a + 12; 15 | b = 9 + b; 16 | c = c + 7; 17 | 18 | */ 19 | 20 | let a = 3; 21 | let b = 17; 22 | let c = 12; 23 | 24 | a += 12; 25 | b += 9; 26 | c += 7; 27 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/060_comparison_with_the_equality_operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // There are many comparison operators in JavaScript. All of these operators return a boolean true or false value. 4 | 5 | // Task: Add the equality operator to the indicated line so that the function will return the string Equal when val is equivalent to 12. 6 | 7 | // Setup 8 | function testEqual(val) { 9 | if (val == 12) { 10 | return "Equal"; 11 | } 12 | return "Not Equal"; 13 | } 14 | 15 | console.log(testEqual(10)); 16 | console.log(testEqual(12)); 17 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/008_case_sensitivity_in_variables.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // All variables and function names are case sensitive 4 | 5 | // Task: Modify the existing declarations and assignments so their names use camelCase. 6 | /* 7 | var StUdLyCapVaR; 8 | var properCamelCase; 9 | var TitleCaseOver; 10 | 11 | STUDLYCAPVAR = 10; 12 | PRoperCAmelCAse = "A String"; 13 | tITLEcASEoVER = 9000;*/ 14 | 15 | var studlyCapVar; 16 | var properCamelCase; 17 | var titleCaseOver; 18 | 19 | studlyCapVar = 10; 20 | properCamelCase = "A String"; 21 | titleCaseOver = 9000; 22 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/034_understanding_string_immutability.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // In JavaScript, String values are immutable, which means that they cannot be altered once created. 4 | 5 | /* 6 | Task: Correct the assignment to myStr so it contains the string value of Hello World using the approach shown in the example above. 7 | 8 | // Setup 9 | let myStr = "Jello World"; 10 | 11 | // Only change code below this line 12 | myStr[0] = "H"; // Change this line 13 | // Only change code above this line 14 | 15 | */ 16 | 17 | let myStr = "Jello World"; 18 | myStr= "Hello World"; 19 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/088_add_new_properties_to_javaScript_object.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // You can add new properties to existing JavaScript objects the same way you would modify them. 4 | 5 | // Task: Add a bark property to myDog and set it to a dog sound, such as "woof". You may use either dot or bracket notation. 6 | 7 | const myDog = { 8 | "name": "Happy Coder", 9 | "legs": 4, 10 | "tails": 1, 11 | "friends": ["freeCodeCamp Campers"] 12 | }; 13 | 14 | myDog.bark = "Bow-wow"; 15 | console.log("The value of bark property in myDog object is: ", myDog.bark); 16 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/037_use_bracket_notation_to_find_the_nth_to_last_character_in_a_string.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | Task: Use bracket notation to find the second-to-last character in the lastName string. 5 | 6 | // Setup 7 | const lastName = "Lovelace"; 8 | 9 | // Only change code below this line 10 | const secondToLastLetterOfLastName = lastName; // Change this line 11 | 12 | */ 13 | 14 | const lastName = "Lovelace"; 15 | const secondToLastLetterOfLastName = lastName[lastName.length - 2]; 16 | console.log("Second to last letter of last name is: ", secondToLastLetterOfLastName); 17 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/031_appending_variables_to_string.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Appending Variables to Strings 4 | 5 | // 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. 6 | 7 | /*Task: Set someAdjective to a string of at least 3 characters and append it to myStr using the += operator. 8 | 9 | const someAdjective = ""; 10 | let myStr = "Learning to code is "; 11 | 12 | */ 13 | 14 | const someAdjective = "cool"; 15 | let myStr = "Learning to code is "; 16 | myStr += someAdjective; 17 | console.log("My String", myStr); 18 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/048_shopping_list.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Create a shopping list in the variable myList. The list should be a multi-dimensional array containing several sub-arrays. 4 | // 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. 5 | // ["Chocolate Bar", 15] 6 | // There should be at least 5 sub-arrays in the list. 7 | 8 | const myList = []; 9 | myList.push(["Chocolate Bar", 15]); 10 | myList.push(["Pasta", 3]); 11 | myList.push(["Coca", 6]); 12 | myList.push(["Bread", 1]); 13 | myList.push(["Eggs", 12]); 14 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/094_accessing_nested_arrays.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Task: Using dot and bracket notation, set the variable secondTree to the second item in the trees list from the myPlants object. 4 | 5 | const myPlants = [ 6 | { 7 | type: "flowers", 8 | list: [ 9 | "rose", 10 | "tulip", 11 | "dandelion" 12 | ] 13 | }, 14 | { 15 | type: "trees", 16 | list: [ 17 | "fir", 18 | "pine", 19 | "birch" 20 | ] 21 | } 22 | ]; 23 | 24 | const secondTree = myPlants[1].list[1]; 25 | console.log(secondTree); 26 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/071_introducing_else_statement.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | 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. 5 | With an else statement, an alternate block of code can be executed.*/ 6 | 7 | // Task: Combine the if statements into a single if/else statement. 8 | 9 | function testElse(val) { 10 | let result = ""; 11 | if (val > 5) { 12 | result = "Bigger than 5"; 13 | } 14 | else { 15 | result = "5 or Smaller"; 16 | } 17 | return result; 18 | } 19 | 20 | testElse(4); 21 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/087_updating_object_properties.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // After you've created a JavaScript object, you can update its properties at any time just like you would update any other variable. You can use either dot or bracket notation to update. 4 | 5 | // Task: Update the myDog object's name property. Let's change her name from Coder to Happy Coder. You can use either dot or bracket notation. 6 | 7 | const myDog = { 8 | "name": "Coder", 9 | "legs": 4, 10 | "tails": 1, 11 | "friends": ["freeCodeCamp Campers"] 12 | }; 13 | 14 | myDog["name"] = "Happy Coder"; 15 | console.log("My dog name is: ", myDog["name"]); 16 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/073_logical_order_in_if_else_statements.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | Order is important in if, else if statements. 5 | The function is executed from top to bottom so you will want to be careful of what statement comes first. 6 | */ 7 | 8 | // Task: Change the order of logic in the function so that it will return the correct statements in all cases. 9 | 10 | function orderMyLogic(val) { 11 | if (val < 5) { 12 | return "Less than 5"; 13 | } else if (val < 10) { 14 | return "Less than 10"; 15 | } else { 16 | return "Greater than or equal to 10"; 17 | } 18 | } 19 | 20 | orderMyLogic(7); 21 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/081_return_early_pattern_for_functions.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | Task: Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined. 5 | 6 | // Setup 7 | function abTest(a, b) { 8 | // Only change code below this line 9 | 10 | 11 | 12 | // Only change code above this line 13 | 14 | return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2)); 15 | } 16 | 17 | abTest(2,2);*/ 18 | 19 | function abTest(a, b) { 20 | if( a < 0 || b < 0) return; 21 | return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2)); 22 | } 23 | 24 | abTest(2,2); 25 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/036_use_bracket_notation_to_find_the_last_character_in_a_string.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // In order to get the last letter of a string, you can subtract one from the string's length. 4 | 5 | /* 6 | 7 | Task: Use bracket notation to find the last character in the lastName variable. 8 | 9 | // Setup 10 | const lastName = "Lovelace"; 11 | 12 | // Only change code below this line 13 | const lastLetterOfLastName = lastName; // Change this line 14 | 15 | */ 16 | 17 | const lastName = "Lovelace"; 18 | const lastLetterOfLastName = lastName[lastName.length - 1]; 19 | console.log("Last letter of last name is: ", lastLetterOfLastName); 20 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/032_find_length_of_a_string.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // You can find the length of a String value by writing .length after the string variable or string literal. 4 | /* 5 | 6 | Task: Use the .length property to count the number of characters in the lastName variable and assign it to lastNameLength. 7 | 8 | // Setup 9 | let lastNameLength = 0; 10 | const lastName = "Lovelace"; 11 | 12 | // Only change code below this line 13 | lastNameLength = lastName; 14 | 15 | */ 16 | 17 | 18 | let lastNameLength = 0; 19 | const lastName = "Lovelace"; 20 | lastNameLength = lastName.length; 21 | console.log("Last name length is: ", lastNameLength); 22 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/002_declare_javascript_variables.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /* 3 | JavaScript provides eight different data types which are: 4 | 5 | undefined, 6 | null, 7 | boolean, 8 | string, 9 | symbol, 10 | bigint, 11 | number, 12 | object*/ 13 | 14 | /* Variables are similar to the x and y variables you use in mathematics, which means they're a simple name to represent the data we want to refer to. 15 | 'Computer variables differ from mathematical variables in that they can store different values at different times. 16 | We tell JavaScript to create or declare a variable by putting the keyword var 17 | */ 18 | 19 | var myName; 20 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/035_use_bracket_notation_to_find_the_nth_character_in_a_string.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // You can also use bracket notation to get the character at other positions within a string 4 | 5 | /* 6 | Task: Let's try to set thirdLetterOfLastName to equal the third letter of the lastName variable using bracket notation. 7 | 8 | // Setup 9 | const lastName = "Lovelace"; 10 | 11 | // Only change code below this line 12 | const thirdLetterOfLastName = lastName; // Change this line 13 | 14 | */ 15 | 16 | const lastName = "Lovelace"; 17 | const thirdLetterOfLastName = lastName[2]; 18 | console.log("Third letter of last name: ", thirdLetterOfLastName); 19 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/046_manipulate_arrays_with_shift.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // pop() always removes the last element of an array. What if you want to remove the first? 4 | // That's where .shift() comes in. It works just like .pop(), except it removes the first element instead of the last. 5 | 6 | 7 | // Task: Use the .shift() function to remove the first item from myArray and assign the "shifted off" value to a new variable, removedFromMyArray. 8 | 9 | // Setup 10 | const myArray = [["John", 23], ["dog", 3]]; 11 | // Only change code below this line 12 | const removedFromMyArray = myArray.shift(); 13 | console.log("Shifted value is: ", removedFromMyArray); 14 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/055_understanding_undefined_value_returned_from_a_function.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // A function can include the return statement but it does not have to. 4 | // In the case that the function doesn't have a return statement, when you call it, the function processes the inner code but the returned value is undefined. 5 | 6 | // Task: Create a function addFive without any arguments. This function adds 5 to the sum variable, but its returned value is undefined. 7 | 8 | // Setup 9 | let sum = 0; 10 | function addThree() { 11 | sum = sum + 3; 12 | } 13 | 14 | function addFive() { 15 | sum += 5; 16 | } 17 | 18 | addThree(); 19 | addFive(); 20 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/083_build_javaScript_objects.js: -------------------------------------------------------------------------------- 1 | "use strict" 2 | 3 | // Objects are similar to arrays, except that instead of using indexes to access and modify their data, you access the data in objects through what are called properties. 4 | 5 | /* 6 | Task: Make an object that represents a dog called myDog which contains the properties name (a string), legs, tails and friends. 7 | You can set these object properties to whatever values you want, as long as name is a string, legs and tails are numbers, and friends is an array.*/ 8 | 9 | const myDog = { 10 | name: "Max", 11 | legs: 4, 12 | tails: 1, 13 | friends: ["Joe", "Ana", "Bob"] 14 | }; 15 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/041_access_array_data_with_indexes.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // We can access the data inside arrays using indexes 4 | // Array indexes are written in the same bracket notation that strings use, except that instead of specifying a character, they are specifying an entry in the array. 5 | // Like strings, arrays use zero-based indexing, so the first element in an array has an index of 0. 6 | 7 | 8 | // Task: Create a variable called myData and set it to equal the first value of myArray using bracket notation. 9 | 10 | const myArray = [50, 60, 70]; 11 | const myData = myArray[0]; 12 | 13 | console.log("Fist element of: " + myArray + "is: " + myData); 14 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/069_comparisons_with_the_logical_and_operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Sometimes you will need to test more than one thing at a time. The logical and operator (&&) returns true if and only if the operands to the left and right of it are true. 4 | 5 | // Task: Replace the two if statements with one statement, using the && operator, which will return the string Yes if val is less than or equal to 50 and greater than or equal to 25. 6 | // Otherwise, will return the string No. 7 | 8 | function testLogicalAnd(val) { 9 | if (val <= 50 && val >= 25) { 10 | return "Yes"; 11 | } 12 | return "No"; 13 | } 14 | 15 | testLogicalAnd(10); 16 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/086_accessing_object_properties_with_variables.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Another use of bracket notation on objects is to access a property which is stored as the value of a variable. This can be very useful for iterating through an object's properties or when accessing a lookup table. 4 | 5 | // Task: Set the playerNumber variable to 16. Then, use the variable to look up the player's name and assign it to player. 6 | 7 | // Setup 8 | const testObj = { 9 | 12: "Namath", 10 | 16: "Montana", 11 | 19: "Unitas" 12 | }; 13 | 14 | const playerNumber = 16; 15 | const player = testObj[playerNumber]; 16 | 17 | console.log("Player is: ", player); 18 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/110_use_the_conditional_operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | The conditional operator, also called the ternary operator, can be used as a one line if-else expression. 5 | The syntax is a ? b : c, where a is the condition, b is the code to run when the condition returns true, and c is the code to run when the condition returns false.*/ 6 | 7 | 8 | // Task: Use the conditional operator in the checkEqual function to check if two numbers are equal or not. The function should return either the string Equal or the string Not Equal. 9 | 10 | function checkEqual(a, b) { 11 | return a === b ? "Equal" : "Not Equal" 12 | } 13 | 14 | checkEqual(1, 2); 15 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/063_comparison_with_the_inequality_operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // The inequality operator (!=) is the opposite of the equality operator. 4 | // It means not equal and returns false where equality would return true and vice versa. Like the equality operator, the inequality operator will convert data types of values while comparing. 5 | 6 | 7 | // Task: Add the inequality operator != in the if statement so that the function will return the string Not Equal when val is not equivalent to 99. 8 | 9 | function testNotEqual(val) { 10 | if (val != 99) { 11 | return "Not Equal"; 12 | } 13 | return "Equal"; 14 | } 15 | 16 | testNotEqual(10); 17 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/092_manipulating_complex_objects.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Task: Add a new album to the myMusic array. Add artist and title strings, release_year number, and a formats array of strings. 4 | 5 | const myMusic = [ 6 | { 7 | "artist": "Billy Joel", 8 | "title": "Piano Man", 9 | "release_year": 1973, 10 | "formats": [ 11 | "CD", 12 | "8T", 13 | "LP" 14 | ], 15 | "gold": true 16 | } 17 | ]; 18 | myMusic.push({ 19 | "artist": "Anson", 20 | "title": "Emerald Eyes", 21 | "release_year": 2019, 22 | "formats": [ 23 | "CD", 24 | "LP" 25 | ], 26 | }) 27 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/064_comparison_with_the_strict_inequality_operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 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. 4 | // The strict inequality operator will not convert data types. 5 | 6 | // Task: Add the strict inequality operator to the if statement so the function will return the string Not Equal when val is not strictly equal to 17 7 | 8 | function testStrictNotEqual(val) { 9 | if (val !== 17) { 10 | return "Not Equal"; 11 | } 12 | return "Equal"; 13 | } 14 | 15 | testStrictNotEqual(10); 16 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/043_access_multi_dimensional_array_with_indexes.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // One way to think of a multi-dimensional array, is as an array of arrays. 4 | // When you use brackets to access your array, the first set of brackets refers to the entries in the outer-most (the first level) array, and each additional pair of brackets refers to the next level of entries inside. 5 | 6 | 7 | // Task: Using bracket notation select an element from myArray such that myData is equal to 8. 8 | 9 | const myArray = [ 10 | [1, 2, 3], 11 | [4, 5, 6], 12 | [7, 8, 9], 13 | [[10, 11, 12], 13, 14], 14 | ]; 15 | 16 | const myData = myArray[2][1]; 17 | console.log("My data: ", myData); 18 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/070_comparisons_with_the_logical_or_operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | The logical or operator (||) returns true if either of the operands is true. 5 | Otherwise, it returns false. 6 | The logical or operator is composed of two pipe symbols: (||). 7 | This can typically be found between your Backspace and Enter keys.*/ 8 | 9 | 10 | // Task: which returns the string Outside if val is not between 10 and 20, inclusive. Otherwise, return the string Inside. 11 | 12 | function testLogicalOr(val) { 13 | // Only change code below this line 14 | 15 | if (val < 10 || val > 20) { 16 | return "Outside"; 17 | } 18 | return "Inside"; 19 | } 20 | 21 | testLogicalOr(15); 22 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/067_comparison_with_the_less_than_operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | The less than operator (<) compares the values of two numbers. 5 | If the number to the left is less than the number to the right, it returns true. Otherwise, it returns false. 6 | Like the equality operator, the less than operator converts data types while comparing.*/ 7 | 8 | 9 | // Task: Add the less than operator to the indicated lines so that the return statements make sense. 10 | 11 | function testLessThan(val) { 12 | if (val < 25) { 13 | return "Under 25"; 14 | } 15 | if (val < 55) { 16 | return "Under 55"; 17 | } 18 | return "55 or Over"; 19 | } 20 | 21 | testLessThan(10); 22 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/033_use_brack_notation_to_find_the_first_character_in_a_string.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // You can get the value of the first letter of the string by using string[0] 4 | 5 | 6 | /* 7 | 8 | Task: Use bracket notation to find the first character in the lastName variable and assign it to firstLetterOfLastName. 9 | 10 | // Setup 11 | let firstLetterOfLastName = ""; 12 | const lastName = "Lovelace"; 13 | 14 | // Only change code below this line 15 | firstLetterOfLastName = lastName; // Change this line 16 | 17 | */ 18 | 19 | let firstLetterOfLastName = ""; 20 | const lastName = "Lovelace"; 21 | firstLetterOfLastName = lastName[0]; 22 | console.log("First letter of last name: ", firstLetterOfLastName); 23 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/084_accessing_object_properties_with_dot_notation.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // There are two ways to access the properties of an object: dot notation (.) and bracket notation ([]), similar to an array. 4 | 5 | // Task: Read in the property values of testObj using dot notation. Set the variable hatValue equal to the object's property hat and set the variable shirtValue equal to the object's property shirt. 6 | 7 | // Setup 8 | const testObj = { 9 | "hat": "ballcap", 10 | "shirt": "jersey", 11 | "shoes": "cleats" 12 | }; 13 | 14 | const hatValue = testObj.hat; 15 | const shirtValue = testObj.shirt; 16 | 17 | console.log("Hat value is: ", hatValue); 18 | console.log("Shirt value is: ", shirtValue); 19 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/045_manipulate_array_with_pop.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // Another way to change the data in an array is with the .pop() function. 4 | // .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. 5 | 6 | // Task: Use the .pop() function to remove the last item from myArray and assign the popped off value to a new variable, removedFromMyArray. 7 | 8 | // Setup 9 | const myArray = [["John", 23], ["cat", 2]]; 10 | // Only change code below this line 11 | const removedFromMyArray = myArray.pop(); 12 | console.log("'Element removed frm the array is:", removedFromMyArray); 13 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/065_comparison_with_the_grater_than_operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | The greater than operator (>) compares the values of two numbers. 5 | If the number to the left is greater than the number to the right, it returns true. Otherwise, it returns false. 6 | Like the equality operator, the greater than operator will convert data types of values while comparing.*/ 7 | 8 | // Task: Add the greater than operator to the indicated lines so that the return statements make sense. 9 | 10 | function testGreaterThan(val) { 11 | if (val > 100) { 12 | return "Over 100"; 13 | } 14 | if (val > 10) { 15 | return "Over 10"; 16 | } 17 | return "10 or Under"; 18 | } 19 | 20 | testGreaterThan(10); 21 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/062_practice_comparing_different_values.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // If the values being compared are not of the same type, the equality operator will perform a type conversion, and then evaluate the values. 4 | // However, the strict equality operator will compare both the data type and value as-is, without converting one type to the other. 5 | 6 | 7 | // Task: The compareEquality function in the editor compares two values using the equality operator. Modify the function so that it returns the string Equal only when the values are strictly equal. 8 | 9 | function compareEquality(a, b) { 10 | if (a === b) { 11 | return "Equal"; 12 | } 13 | return "Not Equal"; 14 | } 15 | 16 | compareEquality(10, "10"); 17 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/093_accessing_nested_objects.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // The sub-properties of objects can be accessed by chaining together the dot or bracket notation. 4 | 5 | // Task: Access the myStorage object and assign the contents of the glove box property to the gloveBoxContents variable. Use dot notation for all properties where possible, otherwise use bracket notation. 6 | 7 | const myStorage = { 8 | "car": { 9 | "inside": { 10 | "glove box": "maps", 11 | "passenger seat": "crumbs" 12 | }, 13 | "outside": { 14 | "trunk": "jack" 15 | } 16 | } 17 | }; 18 | 19 | const gloveBoxContents = myStorage.car.inside["glove box"]; 20 | console.log(gloveBoxContents); 21 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/091_testing_objects_for_properties.js: -------------------------------------------------------------------------------- 1 | "use strict"; 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. .hasOwnProperty() returns true or false if the property is found or not. 4 | 5 | // Task: Modify the function checkObj to test if an object passed to the function (obj) contains a specific property (checkProp). If the property is found, return that property's value. If not, return "Not Found". 6 | 7 | function checkObj(obj, checkProp) { 8 | if(obj.hasOwnProperty(checkProp)) { 9 | return obj[checkProp]; 10 | } else { 11 | return "Not Found"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/007_uninitialized_variables.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | Understanding Uninitialized Variables 5 | 6 | When JavaScript variables are declared, they have an initial value of undefined. 7 | Mathematical operation on an undefined variable will be NaN which means "Not a Number". 8 | Concatenate a string with an undefined variable, you will get a literal string of undefined.*/ 9 | 10 | // Task: Initialize the three variables a, b, and c with 5, 10, and "I am a" respectively so that they will not be undefined. 11 | 12 | // Only change code below this line 13 | var a; 14 | var b; 15 | var c; 16 | 17 | // Only change code above this line 18 | a = 5; 19 | b = 10; 20 | c = "I am a"; 21 | 22 | a = a + 1; 23 | b = b + 5; 24 | c = c + " String!"; 25 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/061_comparison_with_the_strict_equality_operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | Strict equality (===) is the counterpart to the equality operator (==). 5 | However, unlike the equality operator, which attempts to convert both values being compared to a common type, 6 | the strict equality operator does not perform a type conversion.*/ 7 | 8 | // Task: Use the strict equality operator in the if statement so the function will return the string Equal when val is strictly equal to 7. 9 | 10 | // Setup 11 | function testStrict(val) { 12 | if (val === 7) { 13 | return "Equal"; 14 | } 15 | return "Not Equal"; 16 | } 17 | 18 | console.log(testStrict(10)); 19 | console.log(testStrict("7")); 20 | console.log(testStrict(7)); 21 | 22 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/053_local_scope_and_functions.js: -------------------------------------------------------------------------------- 1 | "use strict"; 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 | /* 6 | Task: The editor has two console.logs to help you see what is happening. 7 | Check the console as you code to see how it changes. Declare a local variable myVar inside myLocalScope and run the tests. 8 | */ 9 | 10 | function myLocalScope() { 11 | // Only change code below this line 12 | const myVar = 5; 13 | console.log('inside myLocalScope', myVar); 14 | } 15 | myLocalScope(); 16 | // Run and check the console 17 | // myVar is not defined outside of myLocalScope 18 | console.log('outside myLocalScope', myVar); 19 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/004_assigning_the_value_of_one_variable_to_another.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | After a value is assigned to a variable using the assignment operator, you can assign the value of that variable to another variable using the assignment operator. 5 | 6 | var myVar; 7 | myVar = 5; 8 | var myNum; 9 | myNum = myVar; 10 | 11 | The above declares a myVar variable with no value, then assigns it the value 5. 12 | Next, a variable named myNum is declared with no value. 13 | Then, the contents of myVar (which is 5) is assigned to the variable myNum. 14 | Now, myNum also has the value of 5. 15 | */ 16 | 17 | // Task: Assign the contents of a to variable b. 18 | // Setup 19 | var a; 20 | a = 7; 21 | var b; 22 | 23 | // Only change code below this line 24 | b = a; 25 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/074_chaining_if_else_statements.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // if/else statements can be chained together for complex logic 4 | 5 | /* 6 | Task: Write chained if/else if statements to fulfill the following conditions: 7 | 8 | num < 5 - return Tiny 9 | num < 10 - return Small 10 | num < 15 - return Medium 11 | num < 20 - return Large 12 | num >= 20 - return Huge*/ 13 | 14 | function testSize(num) { 15 | if(num < 5) { 16 | return "Tiny" 17 | } else if (num < 10) { 18 | return "Small" 19 | } else if (num < 15) { 20 | return "Medium" 21 | } else if (num < 20) { 22 | return "Large" 23 | } else if (num >= 20) { 24 | return "Huge" 25 | } else { 26 | return "Change Me"; 27 | } 28 | } 29 | 30 | testSize(7); 31 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/029_concatenating_strings_with_the_plus_equals_operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // We can also use the += operator to concatenate a string onto the end of an existing string variable. 3 | // This can be very helpful to break a long string over several lines. 4 | 5 | /* 6 | Task: Build myStr over several lines by concatenating these two strings: This is the first sentence. and 7 | This is the second sentence. using the += operator. Use the += operator similar to how it is shown in the 8 | example and be sure to include a space between the two strings. Start by assigning the first string to myStr, then add on the second string. 9 | */ 10 | 11 | let myStr; 12 | let myStr = "This is the first sentence."; 13 | myStr += " This is the second sentence."; 14 | 15 | console.log("My string", myStr) 16 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/026_quoting_strings_with_single_quotes.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // String values in JavaScript may be written with single or double quotes, as long as you start and end with the same type of quote. 4 | // Unlike some other programming languages, single and double quotes work the same in JavaScript. 5 | 6 | /* 7 | Task: Change the provided string to a string with single quotes at the beginning and end and no escape characters. 8 | Right now, the tag in the string uses double quotes everywhere. 9 | You will need to change the outer quotes to single quotes so you can remove the escape characters. 10 | 11 | const myStr = "Link";*/ 12 | 13 | const myStr = 'Link'; 14 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/066_comparison_with_the_grater_than_or_equal_to_operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /* 3 | The greater than or equal to operator (>=) compares the values of two numbers. 4 | If the number to the left is greater than or equal to the number to the right, it returns true. Otherwise, it returns false. 5 | Like the equality operator, the greater than or equal to operator will convert data types while comparing.*/ 6 | 7 | // Task: Add the greater than or equal to operator to the indicated lines so that the return statements make sense. 8 | 9 | function testGreaterOrEqual(val) { 10 | if (val >= 20) { 11 | return "20 or Over"; 12 | } 13 | 14 | if (val >= 10) { 15 | return "10 or Over"; 16 | } 17 | 18 | return "Less than 10"; 19 | } 20 | 21 | testGreaterOrEqual(10); 22 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/085_accessing_object_properties_with_bracket_notation.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | // The second way to access the properties of an object is bracket notation ([]). If the property of the object you are trying to access has a space in its name, you will need to use bracket notation. 4 | 5 | // Task: Read the values of the properties an entree and the drink of testObj using bracket notation and assign them to entreeValue and drinkValue respectively. 6 | 7 | // Setup 8 | const testObj = { 9 | "an entree": "hamburger", 10 | "my side": "veggies", 11 | "the drink": "water" 12 | }; 13 | 14 | const entreeValue = testObj["an entree"]; 15 | const drinkValue = testObj["the drink"]; 16 | 17 | console.log("Entree value is: ", entreeValue); 18 | console.log("Drink value is: ", drinkValue); 19 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/068_comparison_with_the_less_than_or_equal_to_operator.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /* 4 | The less than or equal to operator (<=) compares the values of two numbers. 5 | If the number to the left is less than or equal to the number to the right, it returns true. 6 | If the number on the left is greater than the number on the right, it returns false. 7 | Like the equality operator, the less than or equal to operator converts data types.*/ 8 | 9 | // Task: Add the less than or equal to operator to the indicated lines so that the return statements make sense. 10 | 11 | function testLessOrEqual(val) { 12 | if (val <= 12) { 13 | return "Smaller Than or Equal to 12"; 14 | } 15 | if (val <= 24) { 16 | return "Smaller Than or Equal to 24"; 17 | } 18 | return "More Than 24"; 19 | } 20 | 21 | testLessOrEqual(10); 22 | -------------------------------------------------------------------------------- /01_Basic_JavaScript/038_word_blanks.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | /*Task: In this challenge, we provide you with a noun, a verb, an adjective and an adverb. You need to form a complete sentence using words of your choice, along with the words we provide. 4 | You will need to use the string concatenation operator + to build a new string, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb. You will then assign the formed string to the wordBlanks variable. You should not change the words assigned to the variables. 5 | You will also need to account for spaces in your string, so that the final sentence has spaces between all the words. The result should be a complete sentence.*/ 6 | 7 | const myNoun = "dog"; 8 | const myAdjective = "big"; 9 | const myVerb = "ran"; 10 | const myAdverb = "quickly"; 11 | 12 | const wordBlanks = "The " + myNoun + " " + myAdjective + " " + myVerb + " " + myAdverb; 13 | -------------------------------------------------------------------------------- /02_ES6/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |