### Runnable C++ example: Calculate e^1 with exp() Source: https://github.com/codecademy/docs/blob/main/content/cpp/concepts/math-functions/terms/exp/exp.md A runnable C++ codebyte example showcasing the `exp()` function to calculate `e` raised to the power of 1. It illustrates the basic setup with `` and `` headers, and outputs the computed value. ```cpp #include #include int main() { double x = 1; double result; result = exp(x); std::cout << "The exp of " << x << " is " << result << "\n"; } ``` -------------------------------- ### JavaScript Example: Get Property Descriptor Source: https://github.com/codecademy/docs/blob/main/content/javascript/concepts/objects/terms/getOwnPropertyDescriptor/getOwnPropertyDescriptor.md This JavaScript example demonstrates how to use `Object.getOwnPropertyDescriptor()` to retrieve the descriptor for the 'name' property of a `person` object. It shows the setup of a simple object and the call to the method, logging the resulting descriptor to the console. ```JavaScript const person = { name: "Jane", age: 21 }; const descriptor = Object.getOwnPropertyDescriptor(person, 'name'); console.log(descriptor) ``` -------------------------------- ### SQL CREATE TABLE Syntax Source: https://github.com/codecademy/docs/blob/main/content/sql/concepts/commands/terms/create-table/create-table.md Illustrates the general syntax for the `CREATE TABLE` command, showing how to define the table name and column definitions. ```pseudo CREATE TABLE table_name ( column_name column_definition, column_name column_definition, ... ); ``` -------------------------------- ### Get Start of Day as Instant in Kotlin Source: https://github.com/codecademy/docs/blob/main/content/kotlin/concepts/datetime/terms/atStartOfDayIn/atStartOfDayIn.md Demonstrates the syntax and usage of the `LocalDate.atStartOfDayIn()` function in Kotlin's `kotlinx.datetime` library. It shows how to obtain an `Instant` representing the start of a specific `LocalDate` in a given `TimeZone`, along with an example and its expected console output. ```pseudo fun LocalDate.atStartOfDayIn(TimeZone): Instant ``` ```kotlin import kotlinx.datetime.* fun main() { val todaysDate = LocalDate(2023, 11, 18) val myTimeZone = TimeZone.UTC val startOfToday = todaysDate.atStartOfDayIn(myTimeZone) println("Start of the day November 18th, 2023 in UTC is: $startOfToday") } ``` ```shell Start of the day November 18th, 2023 in UTC is: 2023-11-18T00:00Z ``` -------------------------------- ### Console output for C# String.StartsWith() example Source: https://github.com/codecademy/docs/blob/main/content/c-sharp/concepts/strings/terms/startswith/startswith.md Shows the expected console output from the C# example demonstrating the `String.StartsWith()` method, illustrating the boolean results for different comparison scenarios. ```shell Simple compare: False Compare using Case/Culture: True Compare using Enumeration: False ``` -------------------------------- ### Python `range()` with Start and Stop Parameters Example Source: https://github.com/codecademy/docs/blob/main/content/python/concepts/built-in-functions/terms/range/range.md Illustrates how to use the `range()` function with both `start` and `stop` parameters. This example generates a sequence of numbers beginning from the specified `start` value up to (but not including) the `stop` value, and then converts the range object to a list. ```Python nums = range(6, 11) print(list(nums)) ``` ```Shell [6, 7, 8, 9, 10] ``` -------------------------------- ### Navigate to a Project Directory Source: https://github.com/codecademy/docs/blob/main/content/git/concepts/init/init.md Illustrates how to change the current working directory to the desired project location. This is a crucial preparatory step before initializing a Git repository, ensuring the repository's root is correctly set. ```pseudo cd go/to/desired/project/directory ``` -------------------------------- ### Console Output for JavaScript String.prototype.padStart() Examples Source: https://github.com/codecademy/docs/blob/main/content/javascript/concepts/strings/terms/padStart/padStart.md This snippet displays the expected console output from the JavaScript examples demonstrating the `String.prototype.padStart()` method. It clearly shows the resulting padded strings for different `targetLength` and `padString` configurations, including default space padding and custom string padding. ```shell Hi There! 00000Hi There! 12Hi There! 123451234512Hi There! ``` -------------------------------- ### Java substring() Example: Extracting from Index to End Source: https://github.com/codecademy/docs/blob/main/content/java/concepts/strings/terms/substring/substring.md Demonstrates how to use the `substring(startIndex)` method in Java to extract a portion of a string starting from a specified index and extending to the end of the original string. This is useful for truncating or getting suffixes. ```Java class Main { public static void main(String[] args) { String text = "Hello, Java!"; String result = text.substring(7); System.out.println("Original string: " + text); System.out.println("Substring starting from index 7: " + result); } } ``` ```shell Original string: Hello, Java! Substring starting from index 7: Java! ``` -------------------------------- ### APIDOC: .padStart() Method Syntax Source: https://github.com/codecademy/docs/blob/main/content/kotlin/concepts/strings/terms/padStart/padStart.md Documents the syntax and parameters for the .padStart() method, which is used to pad the beginning of a string to a specified length with a given character. ```APIDOC String.padStart(length, padChar) - String: The string to be modified. - length: An integer that represents the total length of the string returned (with padding). - padChar: The character to be used (enclosed by '') as padding, defaults to whitespace. ``` -------------------------------- ### Python `range()` with Start, Stop, and Step Parameters Example Source: https://github.com/codecademy/docs/blob/main/content/python/concepts/built-in-functions/terms/range/range.md Shows an advanced usage of the `range()` function, incorporating `start`, `stop`, and `step` parameters. This example demonstrates how to generate a sequence of numbers with a custom starting point, ending point, and increment (step size), converting the result to a list for display. ```Python nums = range(10, 60, 10) print(list(nums)) ``` -------------------------------- ### C++ std::map::begin() Method Reference Source: https://github.com/codecademy/docs/blob/main/content/cpp/concepts/maps/terms/begin/begin.md Detailed reference for the `std::map::begin()` method, including its syntax, parameters, and return value. ```APIDOC map_name.begin(); Parameters: This function does not take any parameters. Return value: - An iterator pointing to the first element in the map container. - If the map is empty, it returns an iterator equivalent to .end(). ``` -------------------------------- ### Comprehensive Java HashSet Operations Example Source: https://github.com/codecademy/docs/blob/main/content/java/concepts/hashset/hashset.md A complete Java program demonstrating various operations on a `HashSet`, including adding elements, removing elements, checking for item existence, getting the set's size, and iterating through its elements. Includes a helper method for initial setup. ```java import java.util.HashSet; public class Main { public static HashSet SetupHashSet() { HashSet result = new HashSet(); result.add("Cabbage"); result.add("Pizza"); result.add("Sausage"); result.add("Potatoes"); result.add("Salad"); return result; } public static void main(String[] args) { HashSet food = SetupHashSet(); food.add("Sausage"); System.out.println(food); } } ``` ```java public static void main(String[] args) { HashSet food = SetupHashSet(); food.remove("Sausage"); System.out.println(food); } ``` ```java public static void main(String[] args) { HashSet food = SetupHashSet(); if (food.contains("Nuts")) { System.out.println("Allergen warning!"); } else { System.out.println("Safe to eat."); } } ``` ```java public static void main(String[] args) { HashSet food = SetupHashSet(); System.out.println(food.size()); food.remove("Sausage"); System.out.println(food.size()); } ``` ```java public static void main(String[] args) { HashSet food = SetupHashSet(); for (String i : food) { System.out.println(i); } } ``` -------------------------------- ### Syntax for Python Thread .start() Method Source: https://github.com/codecademy/docs/blob/main/content/python/concepts/threading/terms/start/start.md This snippet illustrates the general syntax for invoking the `.start()` method on a thread object. It shows the basic structure required to initiate thread execution. ```pseudo thread_object.start() ``` -------------------------------- ### SQL SIMILAR TO Example: Matching String Start Source: https://github.com/codecademy/docs/blob/main/content/sql/concepts/operators/terms/similar-to/similar-to.md Demonstrates how to select rows where a column's value starts with a specific character using the `SIMILAR TO` operator and the `%` wildcard in PostgreSQL. This example selects countries whose names begin with 'M'. ```sql SELECT * FROM countries WHERE country_name SIMILAR TO 'M%'; ``` -------------------------------- ### Python `__init__()` Method Practical Example Source: https://github.com/codecademy/docs/blob/main/content/python/concepts/dunder-methods/terms/init/init.md This Python example showcases the `__init__()` method being implicitly called when a new `Home` class instance is created. It demonstrates how `rooms` and `stories` instance variables are set during initialization and subsequently accessed. ```python class Home: def __init__(self, rooms, stories): # Setting instance variables self.rooms = rooms self.stories = stories home = Home(4, 2) print(home.rooms) print(home.stories) ``` -------------------------------- ### C# example counting months starting with 'J' using String.StartsWith() Source: https://github.com/codecademy/docs/blob/main/content/c-sharp/concepts/strings/terms/startswith/startswith.md An example demonstrating the use of `String.StartsWith()` to count elements in an array that begin with a specific character. It iterates through an array of month names and increments a counter for months starting with 'J'. ```csharp using System; public class CodeByteExample { public static void Main() { string[] months = new string[] {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int j_count = 0; foreach (string month in months) { if (month.StartsWith('J')) { j_count++; } } Console.WriteLine("{0} months starts in the letter 'J'", j_count); } } ``` -------------------------------- ### Shell Output for Go math.Floor() Example Source: https://github.com/codecademy/docs/blob/main/content/go/concepts/math-functions/terms/floor/floor.md Displays the console output generated by executing the provided Go example, illustrating the results of applying `math.Floor()` to different numeric inputs. ```shell The floored value of 8.99 is: 8 The floored value of -3.11 is: -4 The floored value of NaN is: NaN ``` -------------------------------- ### Extracting Substrings with C++ std::string::substr() Source: https://github.com/codecademy/docs/blob/main/content/cpp/concepts/strings/terms/substr/substr.md This C++ example demonstrates the basic usage of the `std::string::substr()` method to extract different portions of a string by specifying the starting position and optional length. It shows how to get a substring from the beginning, from a specific index to the end, and a segment of a given length. ```cpp #include #include using namespace std; int main() { // Original string string original = "Programming in C++"; // Extract a substring starting from index 0 with length 11 string sub1 = original.substr(0, 11); // Extract a substring starting from index 15 to the end string sub2 = original.substr(15); // Extract a substring starting from index 12 with length 2 string sub3 = original.substr(12, 2); // Display the results cout << "Original string: " << original << endl; cout << "Substring 1: " << sub1 << endl; cout << "Substring 2: " << sub2 << endl; cout << "Substring 3: " << sub3 << endl; return 0; } ``` -------------------------------- ### API Documentation for String.StartsWith() Method Source: https://github.com/codecademy/docs/blob/main/content/c-sharp/concepts/strings/terms/startswith/startswith.md Comprehensive API documentation for the `String.StartsWith()` method, detailing its various overloads, parameters, their types, and descriptions, including options for case and culture sensitivity. ```APIDOC String.StartsWith(char) - Determines whether the String instance's first character matches the specified character. - Parameters: - char: An instance of the `Char` structure; represents a single letter. String.StartsWith(string) - Determines whether the start of String instance matches the specified string. - Parameters: - string: An instance of the `String` object. String.StartsWith(string, ignoreCase, culture) - Determines whether the start of String instance matches the specified string, using additional case-sensitive and culture-sensitive criteria. - Parameters: - string: An instance of the `String` object. - ignoreCase: A boolean; if `true` then case is ignored for comparison (e.g., 'a' == 'A'). - culture: An instance of the `System.Globalization.CultureInfo` class which includes culture-specific sort order rules. String.StartsWith(string, comparisonType) - Determines whether the start of String instance matches the specified string, using an enumeration to determine the case- and culture-sensitive criteria. - Parameters: - string: An instance of the `String` object. - comparisonType: An element of the `StringComparison` enumeration which encapsulates the case- and culture-specific criteria; available fields include: - `CurrentCulture`: sets the current culture rules. - `CurrentCultureIgnoreCase`: sets the current culture rules but ignores case. - `InvariantCulture`: sets the invariant culture's sorting rules (it's a culture that doesn't change based on the user's location). - `InvariantCultureIgnoreCase`: sets the invariant culture rules but ignores case. - `Ordinal`: sets ordinal (binary) sort rules to compare strings. - `OrdinalIgnoreCase`: sets ordinal (binary) sort rules to compare strings but ignores case. ``` -------------------------------- ### SQL SIMILAR TO Example: Matching Multiple String Starts Source: https://github.com/codecademy/docs/blob/main/content/sql/concepts/operators/terms/similar-to/similar-to.md Shows how to use the `SIMILAR TO` operator with parentheses and the `|` (OR) operator to match strings that start with one of several specified patterns in PostgreSQL. This example selects employees whose names begin with 'John' or 'Jane'. ```sql SELECT * FROM employees WHERE name SIMILAR TO '(John|Jane)%'; ``` -------------------------------- ### CSS Grid Item Column Spanning Example Source: https://github.com/codecademy/docs/blob/main/content/css/concepts/grids/terms/grid-column-end/grid-column-end.md This example illustrates how to make a grid item span multiple columns. It uses `grid-column-start` to set the starting column and `grid-column-end` to define the ending column, effectively making the content span three columns starting from the fourth. ```css .foo-text { grid-column-start: 4; grid-column-end: 7; } ``` -------------------------------- ### Runnable example of strings.Compare() with multiple comparisons Source: https://github.com/codecademy/docs/blob/main/content/go/concepts/strings/terms/compare/compare.md A comprehensive Go example demonstrating `strings.Compare()` with different string pairs and printing the results, suitable for direct execution to observe various comparison outcomes. ```go package main import ( "fmt" "strings" ) func main() { firstString := "Hello" secondString := "World" thirdString := "Hello World" result1 := strings.Compare(firstString, secondString) result2 := strings.Compare(firstString, thirdString) result3 := strings.Compare(secondString, thirdString) fmt.Println("The result of comparing 'Hello' and 'World' is:", result1) fmt.Println("The result of comparing 'Hello' and 'Hello World' is:", result2) fmt.Println("The result of comparing 'World' and 'Hello World' is:", result3) } ``` -------------------------------- ### Examples of File Path Syntax Source: https://github.com/codecademy/docs/blob/main/content/general/concepts/file-paths/file-paths.md Illustrates various types of file paths, including absolute paths from the root, absolute paths using tilde notation for the user's home directory, and relative paths using dot notation for current or parent directories. ```File Path /home/user/python/test.py /home/user/website/main/about.html /home/user/projects/js/script.js /home/user/data-analysis/scripts/main.py ``` ```File Path ~/website/main/about.html ~/projects/js/script.js ~/data-analysis/scripts/main.py ``` ```File Path ./about.html ./js/script.js ./scripts/main.py ``` -------------------------------- ### Install Pillow using pip Source: https://github.com/codecademy/docs/blob/main/content/pillow/pillow.md This command installs the Pillow library, the official fork of the Python Imaging Library (PIL), into your Python environment using pip, the Python package installer. This is the standard way to get Pillow up and running. ```shell pip install pillow ``` -------------------------------- ### Demonstrate Math.nextAfter() in Java Source: https://github.com/codecademy/docs/blob/main/content/java/concepts/math-methods/terms/nextAfter/nextAfter.md Provides a practical Java example showcasing the usage of `Math.nextAfter()`. It initializes a `float` `start` value and a `double` `direction` value, then prints the calculated next floating-point number to the console. ```java // Test.java public class Test { public static void main(String args[]) { float start = 1.15f; double direction = 5.37; System.out.println(Math.nextAfter(start, direction)); } } ``` -------------------------------- ### Basic Python Threading with .start() Source: https://github.com/codecademy/docs/blob/main/content/python/concepts/threading/terms/start/start.md This example demonstrates the fundamental usage of Python's `threading` module. It shows how to define a simple function, create a `Thread` object targeting that function, and then activate the thread using the `.start()` method to run concurrently. ```python import threading def do_this(): print("Task done!") my_thread = threading.Thread(target=do_this) my_thread.start() ``` -------------------------------- ### Python string.find() with start and end indices Source: https://github.com/codecademy/docs/blob/main/content/python/concepts/strings/terms/find/find.md Shows advanced usage of the `find()` method by specifying both `start` and `end` indices, including examples with negative indices for `end`. ```python new_string = "I like to eat potato" like_2_length_result = new_string.find("like", 2, len(new_string)) like_4_length_result = new_string.find("like", 4, len(new_string)) like_0_3_result = new_string.find("like", 0, 3) like_0_15_result = new_string.find("like", 0, 15) like_0_last3_result = new_string.find("like", 0, -3) print(like_2_length_result) print(like_4_length_result) print(like_0_3_result) print(like_0_15_result) print(like_0_last3_result) print("") to_0_length_result = new_string.find("to", 0, len(new_string)) to_15_length_result = new_string.find("to", 15, len(new_string)) print(to_0_length_result) print(to_15_length_result) ``` -------------------------------- ### Syntax for JavaScript startsWith() Method Source: https://github.com/codecademy/docs/blob/main/content/javascript/concepts/strings/terms/startsWith/startsWith.md Illustrates the general syntax for the `startsWith()` method, including its required `substring` parameter and optional `position` parameter. ```pseudo myString.startsWith(substring, position); ``` -------------------------------- ### Codebyte Example: Get UTC Day of Month in JavaScript Source: https://github.com/codecademy/docs/blob/main/content/javascript/concepts/dates/terms/getUTCDate/getUTCDate.md An interactive JavaScript example demonstrating the `getUTCDate()` method, showing its usage with a different date ('2024-06-12') and logging the result. ```javascript const myDate = new Date('2024-06-12'); console.log(myDate.getUTCDate()); ``` -------------------------------- ### Initialize a New Git Repository Source: https://github.com/codecademy/docs/blob/main/content/git/concepts/init/init.md Initializes an empty Git repository or reinitializes an existing one in the current directory. This command creates the necessary `.git` subdirectory that contains all of your repository's metadata, enabling Git to track changes. ```shell git init ``` -------------------------------- ### PHP array_splice() Basic Usage Example Source: https://github.com/codecademy/docs/blob/main/content/php/concepts/arrays/terms/array-splice/array-splice.md Illustrates a practical application of `array_splice()` in PHP. This example modifies an array of colors by replacing elements from a specified starting index with new values. ```PHP ``` -------------------------------- ### JavaScript Array slice() with Only Start Index Source: https://github.com/codecademy/docs/blob/main/content/javascript/concepts/arrays/terms/slice/slice.md Shows how `slice()` behaves when only the `start` argument is provided. In this scenario, the method extracts elements from the specified `start` index all the way to the end of the original array. This example creates a new array containing weekend days. ```js const weekDays = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ]; const weekend = weekDays.slice(4); console.log(weekend); ``` -------------------------------- ### Bash Basic Command Structure Source: https://github.com/codecademy/docs/blob/main/content/command-line/concepts/bash/terms/syntax-fundamentals/syntax-fundamentals.md Illustrates the fundamental structure of Bash commands, including options and arguments, and provides a concrete example. ```pseudo command [OPTIONS] arguments ``` ```bash ls -la /home/user ``` -------------------------------- ### C++ std::string::find() with Start Position and string::npos Source: https://github.com/codecademy/docs/blob/main/content/cpp/concepts/strings/terms/find/find.md Illustrates using the optional `position` argument to specify the starting index for the search. This example attempts to find 'izz' starting from index 2, which is outside its actual occurrence, resulting in `string::npos` being returned. ```cpp #include #include int main() { std::string food = "pizzabagel"; std::cout << food.find("izz", 2); } ``` ```shell 18446744073709551615 ``` -------------------------------- ### HTML Ordered List Example with Recipe Steps Source: https://github.com/codecademy/docs/blob/main/content/html/concepts/elements/terms/ol/ol.md Demonstrates a practical application of the `
    ` element in HTML to display a sequence of steps, such as a recipe, where each list item is automatically numbered by default. ```html
    1. Preheat oven to 325° F 👩‍🍳
    2. Drop cookie dough 🍪
    3. Bake for 15 min ⏰
    ``` -------------------------------- ### Python Example: time.sleep() with ctime() for Time Delay Source: https://github.com/codecademy/docs/blob/main/content/python/concepts/time-module/terms/sleep/sleep.md This Python example uses `time.sleep()` to introduce a 5-second delay between printing the start and end times. It leverages `time.ctime()` to display the current time before and after the pause. ```python import time print ("Start : %s" % time.ctime()) time.sleep( 5 ) print ("End : %s" % time.ctime()) ``` -------------------------------- ### Demonstrate Go Slice Declaration and Properties Source: https://github.com/codecademy/docs/blob/main/content/go/concepts/slices/slices.md Comprehensive Go example demonstrating various ways to declare and initialize slices, including from scratch, from an array, and using `make()`. It outputs slice and array data values, length, and capacity for each to illustrate their properties. ```go package main import "fmt" func main() { // Declare and initialize a slice in one line n := []int{1, 2, 3, 4, 5} fmt.Println("New Slice:", n, "Length:", len(n), "Capacity:", cap(n), "\n") // Create a slice from an existing array a := [7]int{1, 2, 3, 4, 5, 6, 7} s := a[2:5] fmt.Println("Array:", a, "Length:", len(a), "Capacity:", cap(a)) fmt.Println("Slice from Array:", s, "Length:", len(s), "Capacity:", cap(s), "\n") // Create an empty slice, setting length and capacity m := make([]int, 3, 8) fmt.Println("Empty Slice:", m, "Length:", len(m), "Capacity:", cap(m), "\n") } ``` -------------------------------- ### Getting Current DateTime in Ruby Source: https://github.com/codecademy/docs/blob/main/content/ruby/concepts/dates/dates.md This Ruby example demonstrates how to obtain the current date and time as a `DateTime` object using the convenient `.now()` method. It provides a quick way to get the current timestamp. ```Ruby puts DateTime.now # Output: 2021-07-30T13:48:56-04:00 ``` -------------------------------- ### Output of Go ToUpper() example Source: https://github.com/codecademy/docs/blob/main/content/go/concepts/strings/terms/toupper/toupper.md Shows the console output generated by the Go example demonstrating the `strings.ToUpper()` function, confirming that the input string "Codecademy" is successfully converted to its uppercase equivalent. ```shell CODECADEMY ``` -------------------------------- ### Kotlin Example: Using .padStart() for string padding Source: https://github.com/codecademy/docs/blob/main/content/kotlin/concepts/strings/terms/padStart/padStart.md Demonstrates how to use the .padStart() method in Kotlin to pad a string. The example shows padding with default whitespace and with a specified character ('-'), illustrating how the method ensures a minimum total string length. The output of this code will be: 'codecademydocs' '----codecademydocs' ```kotlin fun main() { val str = "codecademydocs" val str2 = str.padStart(14) println(str2) val str3 = str.padStart(18, '-') println(str3) } ``` -------------------------------- ### Kotlin Example: Getting Current Date with .todayIn() Source: https://github.com/codecademy/docs/blob/main/content/kotlin/concepts/datetime/terms/todayIn/todayIn.md This Kotlin example demonstrates how to use `Clock.System.todayIn()` in conjunction with `TimeZone.currentSystemDefault()` to retrieve and print the current local date. The output will be similar to '2023-11-21'. ```kotlin import kotlinx.datetime.* fun main() { val myLocalDate = Clock.System.todayIn(timeZone = TimeZone.currentSystemDefault()) println(myLocalDate) } ``` -------------------------------- ### Log 'Hello, World!' to console in JavaScript Source: https://github.com/codecademy/docs/blob/main/documentation/concept-entry-template.md This snippet demonstrates how to print a simple 'Hello, World!' message to the console using JavaScript. It's a basic example often used to verify environment setup and is runnable in a Codecademy codebyte environment. ```js console.log('Hello, World!'); ``` -------------------------------- ### Ruby String Length Example Source: https://github.com/codecademy/docs/blob/main/content/ruby/concepts/strings/terms/length/length.md Demonstrates how to use the .length property in Ruby to get the character count of a string variable and print it to the console. The example initializes a string 'Hi, internet!' and then outputs its length. ```ruby greeting = "Hi, internet!" puts greeting.length ``` -------------------------------- ### Python sum() with custom initial value Source: https://github.com/codecademy/docs/blob/main/content/python/concepts/built-in-functions/terms/sum/sum.md Explains the use of the optional `start` parameter in the Python `sum()` function to add an initial value to the sum of elements in an iterable, showing an example with a list and a specified starting number. ```python numbers = [1, 2, 3, 4, 5] total = sum(numbers, 10) print(total) ``` ```shell 25 ``` -------------------------------- ### Basic Usage Examples of JavaScript String.prototype.padStart() Source: https://github.com/codecademy/docs/blob/main/content/javascript/concepts/strings/terms/padStart/padStart.md This JavaScript code demonstrates various applications of the `String.prototype.padStart()` method. It covers padding with default spaces, a single character ('0'), and a custom multi-character string, illustrating how the padding string repeats or truncates to meet the target length. ```js const originalString = 'Hi There!'; const padString = '12345'; // Case 1: Pad the original string with spaces until the total length is 15 console.log(originalString.padStart(15)); // Case 2: Pad the original string with '0's until the total length is 14 console.log(originalString.padStart(14, '0')); // Case 3: Pad the original string with 'padString' until the total length is 11 console.log(originalString.padStart(11, padString)); // Case 4: Pad the original string with 'padString', repeating it as needed until the total length is 21 console.log(originalString.padStart(21, padString)); ``` -------------------------------- ### JavaScript .substr() Method Usage Examples Source: https://github.com/codecademy/docs/blob/main/content/javascript/concepts/strings/terms/substr/substr.md Provides multiple examples of the `String.prototype.substr()` method in JavaScript, demonstrating extraction with a specified length, without a specified length, and extraction from the end of the string using a negative start index. ```js // Extracting a portion of a string with a specified length. var sentence1 = 'The Intro to JavaScript is fun to learn.'; console.log(sentence1.substr(4, 19)); // Extracting a portion of a string _without_ a specified length. var sentence2 = 'The Intro to JavaScript is fun to learn.'; console.log(sentence2.substr(4)); // Extracting from the end of a string. var sentence3 = 'The Intro to JavaScript is fun to learn.'; console.log(sentence3.substr(-27, 10)); ``` -------------------------------- ### Command Line Output for Python `__main__` Example Source: https://github.com/codecademy/docs/blob/main/content/python/concepts/files/files.md Presents the console output generated when the `example.py` script, which demonstrates the `__name__` and `__main__` variables, is executed from the command line. ```shell Example file: __main__ Imported example file: imported_example_file ``` -------------------------------- ### Display 'Hello, World!' in JavaScript Codebyte Source: https://github.com/codecademy/docs/blob/main/documentation/content-standards.md This snippet demonstrates a fundamental 'Hello, World!' program in JavaScript. It prints the specified string to the console, serving as a basic example for testing the Codebyte environment and illustrating how to include executable code in documentation. ```javascript console.log('Hello, World!'); ``` -------------------------------- ### Valid HTML `id` Attribute Value Example Source: https://github.com/codecademy/docs/blob/main/content/html/concepts/attributes/terms/id/id.md Demonstrates an example of a syntactically valid `id` attribute value, highlighting that it can contain letters, digits, hyphens, underscores, and periods, and must start with a letter. ```HTML

    Hello World

    ``` -------------------------------- ### Go strings.Index() Function Example Source: https://github.com/codecademy/docs/blob/main/content/go/concepts/strings/terms/index/index.md Demonstrates the usage of the `strings.Index()` function in Go to find the starting index of a substring. The example shows cases where the substring is found (returning its index) and not found (returning -1), with corresponding outputs. ```go package main import ( "fmt" "strings" ) func main() { fmt.Println(strings.Index("chandler","and")) fmt.Println(strings.Index("navy","as")) } ``` -------------------------------- ### Recommended Slugs for Command Line Source: https://github.com/codecademy/docs/blob/main/documentation/catalog-content.md Lists the recommended free course and Pro path slugs for content related to Command Line, to be included in file metadata. ```YAML - 'learn-the-command-line' - 'paths/computer-science' ``` -------------------------------- ### JavaScript prompt() Function Usage Example Source: https://github.com/codecademy/docs/blob/main/content/javascript/concepts/window/terms/prompt/prompt.md This example demonstrates how to use the `prompt()` function to get user input in JavaScript. It shows how to store the returned value and handle both cases: when the user provides input and when they cancel the dialog. ```javascript let name = prompt('Please enter your name:'); if (name !== null) { console.log('Hello, ' + name + '!'); } else { console.log("You didn't enter a name."); } ``` -------------------------------- ### SQL LEFT JOIN Example with Customer Orders Source: https://github.com/codecademy/docs/blob/main/content/sql/concepts/commands/terms/left-join/left-join.md Demonstrates a complete SQL example using `LEFT JOIN` to retrieve all customer records and their associated orders. Includes DDL for table creation, DML for data insertion, and the `LEFT JOIN` query, showing how `NULL` values are handled for non-matching records from the right table. ```sql -- Create customers table CREATE TABLE customers ( customer_id INT PRIMARY KEY, customer_name VARCHAR(50), city VARCHAR(50) ); -- Insert sample data INSERT INTO customers (customer_id, customer_name, city) VALUES (1, 'Alice Johnson', 'New York'), (2, 'Bob Smith', 'Los Angeles'), (3, 'Carol Brown', 'Chicago'), (4, 'David Wilson', 'Houston'); -- Create orders table CREATE TABLE orders ( order_id INT PRIMARY KEY, customer_id INT, order_date DATE, total_amount DECIMAL(10, 2) ); -- Insert sample data INSERT INTO orders (order_id, customer_id, order_date, total_amount) VALUES (101, 1, '2024-01-15', 250.00), (102, 2, '2024-01-20', 150.00), (103, 1, '2024-02-01', 300.00); -- LEFT JOIN query to show all customers with their orders SELECT c.customer_id, c.customer_name, c.city, o.order_id, o.order_date, o.total_amount FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id ORDER BY c.customer_id; ``` -------------------------------- ### Syntax for .zfill() method Source: https://github.com/codecademy/docs/blob/main/content/python/concepts/strings/terms/zfill/zfill.md Illustrates the basic syntax for using the .zfill() method, showing how it takes an integer argument for the total desired length and returns a new string. ```pseudo result = string.zfill(total_length) ``` -------------------------------- ### Lua example of string.sub() usage Source: https://github.com/codecademy/docs/blob/main/content/lua/concepts/strings/terms/sub/sub.md Illustrates practical application of `string.sub()` in Lua. It demonstrates extracting a substring using both start and end indices, and another case where only the start index is provided, extending to the end of the string. ```lua local originalString = "Hello, World!" local subString1 = string.sub(originalString, 1, 5) local subString2 = string.sub(originalString, 8) print(subString1) print(subString2) ``` -------------------------------- ### Demonstrate C# Partial Class Usage Source: https://github.com/codecademy/docs/blob/main/content/c-sharp/concepts/classes/classes.md This C# example demonstrates the practical application of partial classes by showing how an instance of a `Calculator` class, whose definition is conceptually split across multiple files, can be instantiated and its methods (`Add`, `Subtract`) invoked. It illustrates how the `Main` method serves as the application's entry point to utilize the combined functionality of a partial class, showcasing the modularity benefits for large or collaborative projects. ```csharp using System; class Program { static void Main() { Calculator calculator = new Calculator(); int result1 = calculator.Add(5, 3); int result2 = calculator.Subtract(10, 4); Console.WriteLine("Addition: " + result1); // Output: Addition: 8 Console.WriteLine("Subtraction: " + result2); // Output: Subtraction: 6 } } ``` -------------------------------- ### Interactive JavaScript reduceRight() Example for Message Construction Source: https://github.com/codecademy/docs/blob/main/content/javascript/concepts/arrays/terms/reduceRight/reduceRight.md An interactive code example demonstrating the `reduceRight()` method to construct a full message by concatenating words from an array. It starts with an `initialValue` of 'learning' and processes the array elements from right to left. ```javascript const codingMessage = ["practice", " ", "of", " ", "lot", " ", "a", " ", "require", ", ", "code", " ", "to", " "]; const fullMessage = codingMessage.reduceRight( (accumulator, currentValue) => accumulator + currentValue, "learning" ); console.log(fullMessage); ``` -------------------------------- ### Python Thread Synchronization with .join() Example Source: https://github.com/codecademy/docs/blob/main/content/python/concepts/threading/terms/join/join.md This Python example demonstrates the use of `threading.Thread.join()` to ensure sequential execution of threads. `thread_A` must complete its `is_divisible` task before `thread_B` starts, preventing concurrent execution and illustrating thread blocking. ```python import threading def is_divisible(dividend, divisor): print("Starting...") if(dividend % divisor == 0): print(True) else: print(False) print("Finished") thread_A = threading.Thread(target=is_divisible, args=(28, 14)) thread_B = threading.Thread(target=is_divisible, args=(34, 7)) thread_A.start() thread_A.join() thread_B.start() thread_B.join() ``` -------------------------------- ### Comprehensive Go Function Examples Source: https://github.com/codecademy/docs/blob/main/content/go/concepts/functions/functions.md Demonstrates various Go function features including single and multiple return values, named return values, passing functions as parameters, and returning functions. Includes a `main` function to illustrate their invocation and interaction. ```Go package main import ( "fmt" ) // Parentheses can be omitted in the returnValue space "string" if there is only one parameter func Hello(name string) string { return "This is being returned with no parentheses. " + name } func MultipleReturns(a int64, b int64) (int64, int64) { return a + b, a - b } func MultipleReturns2(a int64, b int64) (c int64, d int64) { x, y := a+b, a-b c = x d = y return // Return names don't need to be specified if using named return values in func definition } // Passing a function as a parameter func printResult(f func(int64, int64) (int64, int64), a int64, b int64) { c, d := f(a, b) fmt.Println(c, d) } // Functions can return functions as well! func returnFunc() func() { return func() { fmt.Println("This is a function returned by another function.") } } func main() { returnFunc()() printResult(MultipleReturns, 10, 3) fmt.Println(Hello("nice right")) fmt.Println(MultipleReturns(10, 3)) fmt.Println(MultipleReturns2(10, 3)) } ``` ```shell Hey I am a function returned by function sounds cool right? 13 7 check me i dont have parenthesis around my return see nice right 13 7 13 7 Program exited. ``` -------------------------------- ### Basic JavaScript Console Output with Codebyte Source: https://github.com/codecademy/docs/blob/main/documentation/term-entry-template.md Demonstrates a simple 'Hello, World!' program using JavaScript, designed to run within a Codecademy Codebyte interactive block. This example illustrates the basic syntax for printing output to the console. ```javascript console.log('Hello, World!'); ``` -------------------------------- ### PHP substr() Basic Usage Example Source: https://github.com/codecademy/docs/blob/main/content/php/concepts/string-functions/terms/substr/substr.md Demonstrates the basic usage of the PHP `substr()` function to extract a substring from a given string and print it to the console. This example shows how to specify a starting offset and a length to retrieve a specific part of the string. ```php ``` -------------------------------- ### Output for Math.floor() Positive/Negative/Zero Example Source: https://github.com/codecademy/docs/blob/main/content/java/concepts/math-methods/terms/floor/floor.md Shows the console output for the Java example demonstrating `Math.floor()` behavior with positive, negative, and zero inputs. ```shell -4.0 1.0 0.0 ``` -------------------------------- ### Java Example: Extracting Substring from StringBuilder Source: https://github.com/codecademy/docs/blob/main/content/java/concepts/stringbuilder/terms/substring/substring.md This Java example demonstrates the usage of the `substring()` method on a `StringBuilder` object. It initializes a `StringBuilder`, prints its content, and then extracts and prints a specific substring based on start and end indices. ```java import java.util.*; public class Example { public static void main(String[] args) { StringBuilder str = new StringBuilder("Hello World!"); System.out.println(str.toString()); String s1 = str.substring(6,11); System.out.println(s1); } } ``` -------------------------------- ### Recommended Slugs for Go Source: https://github.com/codecademy/docs/blob/main/documentation/catalog-content.md Lists the recommended free course and Pro path slugs for content related to Go, to be included in file metadata. ```YAML - 'learn-go' - 'paths/back-end-engineer-career-path' - 'paths/computer-science' ``` -------------------------------- ### CSS grid-row-end example for spanning rows Source: https://github.com/codecademy/docs/blob/main/content/css/concepts/grids/terms/grid-row-end/grid-row-end.md Illustrates a practical application of `grid-row-end` in CSS. This example demonstrates how to make a content block start on the second row and span a total of four rows by setting `grid-row-start` to 2 and `grid-row-end` to 6. ```CSS .foo-text { grid-row-start: 2; grid-row-end: 6; } ``` -------------------------------- ### C# Example of String.StartsWith() usage Source: https://github.com/codecademy/docs/blob/main/content/c-sharp/concepts/strings/terms/startswith/startswith.md Demonstrates different ways to use the `String.StartsWith()` method in C#, including simple comparison, case/culture-sensitive comparison, and comparison using `StringComparison` enumeration. ```cs using System; using System.Threading; public class Example { public static void Main() { string baseString = "AbCdEfG"; string compareStart = "abc"; bool result; // String.StartsWith(string) result = baseString.StartsWith(compareStart); Console.WriteLine("Simple compare: {0}", result.ToString()); // String.StartsWith(string, ignoreCase, culture) result = baseString.StartsWith(compareStart, true, Thread.CurrentThread.CurrentCulture); Console.WriteLine("Compare using Case/Culture: {0}", result.ToString()); // String.StartsWith(string, comparisonType) result = baseString.StartsWith(compareStart, StringComparison.InvariantCulture); Console.WriteLine("Compare using Enumeration: {0}", result.ToString()); } } ``` -------------------------------- ### Create Rust Slice Omitting Start Index Source: https://github.com/codecademy/docs/blob/main/content/rust/concepts/slices/slices.md Illustrates how to create an immutable slice in Rust that starts from the beginning of an array and extends up to a specified end index. This example slices `[1, 2, 3, 4, 5]` to `[1, 2, 3]`. ```rust fn main() { let my_arr = [1, 2, 3, 4, 5]; let my_slice = &my_arr[..3]; println!("Slice without start index: {:?}", my_slice); } ``` -------------------------------- ### MySQL Table Creation and Data Insertion for HEX() Demonstration Source: https://github.com/codecademy/docs/blob/main/content/mysql/concepts/hex/hex.md SQL commands to create an 'employees' table and insert sample data. This setup is used to demonstrate the application of the `HEX()` function on table columns. ```SQL -- Create a table named 'employees' CREATE TABLE employees ( last_name VARCHAR(50), employee_id INT ); -- Insert data INSERT INTO employees (last_name, employee_id) VALUES ('Smith', 40388), ('Jones', 80666), ('Brown', 64695), ('Miller', 23088), ('Williams', 15312); -- Verify that the data is inserted correctly SELECT * FROM employees; ``` -------------------------------- ### Python Example: Tracking Time with `datetime.time()` and `time.sleep()` Source: https://github.com/codecademy/docs/blob/main/content/python/concepts/dates/terms/time/time.md This Python example demonstrates how to use `datetime.datetime.now().time()` to capture the current time and `time.sleep()` to introduce a delay. It simulates a tea brewing process, showing start and end times with a 3-second pause. ```python import datetime import time # Create a simple timer for brewing tea def brew_tea(): # Get start time start_time = datetime.datetime.now().time() print(f"Starting to brew tea at: {start_time.strftime('%H:%M:%S')}") print("Brewing...") time.sleep(3) # Wait for 3 seconds end_time = datetime.datetime.now().time() print(f"Tea is ready at: {end_time.strftime('%H:%M:%S')}") brew_tea() ``` -------------------------------- ### Starting and interacting with Python's help utility Source: https://github.com/codecademy/docs/blob/main/content/python/concepts/built-in-functions/terms/help/help.md Demonstrates how to invoke Python's interactive help utility by calling `help()` without arguments, displaying the initial welcome message and prompt for further input. ```shell Welcome to Python 3's help utility! If this is your first time using Python, you should definitely check out the tutorial on the internet at https://docs.python.org/3.10/tutorial/. Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To quit this help utility and return to the interpreter, just type "quit". To get a list of available modules, keywords, symbols, or topics, type "modules", "keywords", "symbols", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose name or summary contain a given string such as "spam", type "modules spam". help> ``` -------------------------------- ### PHP array_fill() Codebyte Example: Basic String Fill Source: https://github.com/codecademy/docs/blob/main/content/php/concepts/arrays/terms/array-fill/array-fill.md A runnable PHP example using `array_fill()` to create an array. It fills 5 elements with the string 'Hello', starting from index 0. The `print_r()` function outputs the resulting array to the console. ```php ``` -------------------------------- ### Output of basic math.Exp2() example Source: https://github.com/codecademy/docs/blob/main/content/go/concepts/math-functions/terms/exp2/exp2.md Shows the expected console output when running the basic `math.Exp2()` Go example, demonstrating the results for positive and negative inputs. ```shell 16.0 0.1 ``` -------------------------------- ### Output for Python list() examples Source: https://github.com/codecademy/docs/blob/main/content/python/concepts/built-in-functions/terms/list/list.md Shows the console output for the Python examples demonstrating list creation from a dictionary and an empty list. ```shell ['Python', 'Java', 'HTML'] [] ``` -------------------------------- ### Example: Get Column Count from CSV in R Source: https://github.com/codecademy/docs/blob/main/content/r/concepts/data-frames/terms/ncol/ncol.md Demonstrates how to read a CSV file into an R data frame and then use the `ncol()` function to determine the number of columns. The example includes the R code and its corresponding shell output. ```r # Read file df <- read.csv("patients.csv") # Retrieve number of columns ncol(df) ``` ```shell 3 ``` -------------------------------- ### Output of Basic Expm1() Go Example Source: https://github.com/codecademy/docs/blob/main/content/go/concepts/math-functions/terms/expm1/expm1.md The expected console output when running the basic Expm1() usage example in Go. ```shell 6.4 ``` -------------------------------- ### Get UTC Full Year in JavaScript: Practical Example Source: https://github.com/codecademy/docs/blob/main/content/javascript/concepts/dates/terms/getUTCFullYear/getUTCFullYear.md This example demonstrates the practical application of the `getUTCFullYear()` method. It initializes a `Date` object with a specific UTC timestamp and then extracts and logs the four-digit year to the console, showcasing its direct usage and output. ```js const date = new Date('2023-06-06T10:30:00Z'); const year = date.getUTCFullYear(); console.log(year); ``` -------------------------------- ### Go strings.Join() Example for Interactive Environment Source: https://github.com/codecademy/docs/blob/main/content/go/concepts/strings/terms/join/join.md Provides an example of `strings.Join()` suitable for an interactive code environment (Codebyte), demonstrating how to concatenate multiple words ('Go', 'is', 'awesome!') into a sentence using spaces as separators. ```go package main import ( "fmt" "strings" ) func main() { strs := []string{"Go", "is", "awesome!"} result := strings.Join(strs, " ") fmt.Println(result) } ``` -------------------------------- ### Example: Initializing React State with Property Initializers Source: https://github.com/codecademy/docs/blob/main/content/react/concepts/state/state.md An example showcasing the modern approach of initializing the `state` object directly as a class property in a React component. This method simplifies state setup by eliminating the need for a `constructor()` specifically for state initialization. ```jsx class Car extends React.Component { // No need to use constructor state = { brand: 'Chevrolet', model: 'Malibu', color: 'white', year: 1998, }; // Same rendered JSX } ```