This folder contains JavaScript exercises that focus on program logic, decision-making, and state management. These labs go beyond simple calculations and start working with branching, conditionals, and the flow of execution in a program.
The goal of these exercises is to practice thinking through how a program behaves step-by-step β especially as values change over time.
This lab determines a golferβs score label based on the holeβs par value and the number of strokes taken. It follows standard golf scoring rules and returns a descriptive result such as "Birdie" or "Bogey".
golfScore(5, 4) β Birdie
golfScore(4, 1) β Hole-in-one!
golfScore(4, 7) β Go Home!
golfScore(5, 2) β Albatross
golfScore(3, 3) β Par
golfScore(4, 2) β Eagle
golfScore(4, 5) β Bogey
This lab reinforced the importance of ordering conditions correctly, since the output depends entirely on rule precedence. It highlighted how real-world scoring systems can be modeled in code using structured decision trees, and how early guard conditions prevent incorrect matches later in the flow.
This lab searches a list of contact objects to retrieve a specific property value based on a provided first name. The program follows a clear set of rules to determine whether the contact exists and whether the requested property is valid.
Rather than iterating unnecessarily, the logic prioritizes validation and early exits to ensure predictable and readable behavior.
lookUpProfile("Kristian", "lastName") β "Vos"
lookUpProfile("Sherlock", "likes") β ["Intriguing Cases", "Violin"]
lookUpProfile("Bob", "number") β "No such contact"
lookUpProfile("Akira", "address") β "No such property"
This lab reinforced the importance of validating data in the correct order before attempting to access it. It highlighted how checking for the existence of a contact must come before checking for a property, and how early returns make decision logic easier to read and reason about.
It also demonstrated how real-world lookup behavior can be modeled in code using structured conditional branches, ensuring the program produces clear and predictable responses even when data is missing.
This exercise builds a function that returns the first element in an array that satisfies a provided truth test function.
findElement([1, 3, 5, 8, 9], num => num % 2 === 0) β 8
Array.prototype.find)This lab introduced the concept of higher-order functions by allowing behavior to be passed into a function as an argument. It reinforced how control flow can be delegated using predicate functions, and how early returns can be used to efficiently stop iteration once a condition is met.
This exercise builds a function that generates a text-based pyramid using a specified character, number of rows, and direction flag.
pyramid('o', 4, false);
o;
ooo;
ooooo;
ooooooo;
This lab required careful planning and incremental debugging to manage spacing, alignment, and execution order. It reinforced the importance of breaking complex output problems into smaller steps and reasoning through how control flow affects final results.
This lab simulates a simplified Blackjack card-counting system. The program keeps track of a running count and returns a suggestion based on whether the current count is positive or not.
2 Bet
0 Hold
-1 Hold
if / else if / else branchingThis lab introduced the concept of state persistence across function calls, where each call affects the next outcome. It emphasized thinking about program flow over time rather than a single execution, and showed how simple conditional logic can drive decision-making systems.
This exercise generates Fibonacci numbers up to a specified limit and calculates the sum of only the odd values in the sequence. The function builds the sequence step-by-step while ensuring numbers do not exceed the provided limit.
sumFibs(4) β 5 // 1 + 1 + 3
sumFibs(10) β 10 // 1 + 1 + 3 + 5
sumFibs(75025) β 135721
This lab reinforces the importance of control flow and condition placement when generating sequences. It highlights how a small shift in where a condition is evaluated can significantly change program behavior. The exercise also demonstrates how multiple stages of logicβgeneration, filtering, and accumulationβcan be combined to produce a final result.
These labs strengthened my ability to think in terms of program flow rather than isolated operations. Each exercise required reasoning about how conditions interact, how rule order affects results, and how state can evolve during execution.
Together, they introduced several core programming patterns:
This folder marks the transition from simple syntax practice to structured logical thinking β a foundational skill for building reliable applications.