diff --git a/lesson_06/quiz/src/lesson5.ts b/lesson_06/quiz/src/lesson5.ts index 9ad62bd67..51c0a43e3 100644 --- a/lesson_06/quiz/src/lesson5.ts +++ b/lesson_06/quiz/src/lesson5.ts @@ -38,7 +38,7 @@ export class Lesson5 { [AnswerChoice.C, "To insert an image"], [AnswerChoice.D, "To create a paragraph"], ]), - AnswerChoice.UNANSWERED, + AnswerChoice.B, ); } @@ -52,7 +52,7 @@ export class Lesson5 { [AnswerChoice.C, "alt"], [AnswerChoice.D, "href"], ]), - AnswerChoice.UNANSWERED, + AnswerChoice.C, ); } @@ -66,7 +66,7 @@ export class Lesson5 { [AnswerChoice.C, "
"], [AnswerChoice.D, ""], ]), - AnswerChoice.UNANSWERED, + AnswerChoice.B, ); } @@ -80,7 +80,7 @@ export class Lesson5 { [AnswerChoice.C, ""], [AnswerChoice.D, "
"], ]), - AnswerChoice.UNANSWERED, + AnswerChoice.B, ); } @@ -94,7 +94,7 @@ export class Lesson5 { [AnswerChoice.C, "Computer Style Sheets"], [AnswerChoice.D, "Cascading System Sheets"], ]), - AnswerChoice.UNANSWERED, + AnswerChoice.B, ); } @@ -108,7 +108,7 @@ export class Lesson5 { [AnswerChoice.C, "text-color"], [AnswerChoice.D, "background-color"], ]), - AnswerChoice.UNANSWERED, + AnswerChoice.B, ); } @@ -122,7 +122,7 @@ export class Lesson5 { [AnswerChoice.C, "/* this is a comment */"], [AnswerChoice.D, ""], ]), - AnswerChoice.UNANSWERED, + AnswerChoice.C, ); } @@ -136,7 +136,7 @@ export class Lesson5 { [AnswerChoice.C, "text-size"], [AnswerChoice.D, "text-style"], ]), - AnswerChoice.UNANSWERED, + AnswerChoice.B, ); } @@ -150,7 +150,7 @@ export class Lesson5 { [AnswerChoice.C, "inline-block"], [AnswerChoice.D, "none"], ]), - AnswerChoice.UNANSWERED, + AnswerChoice.B, ); } @@ -164,7 +164,7 @@ export class Lesson5 { [AnswerChoice.C, ""], [AnswerChoice.D, ""], ]), - AnswerChoice.UNANSWERED, + AnswerChoice.A, ); } } @@ -172,3 +172,5 @@ export class Lesson5 { if (!process.env.JEST_WORKER_ID) { new Lesson5().run(); } + + diff --git a/lesson_07/README.md b/lesson_07/README.md index fb6745f2d..ac880e2ed 100644 --- a/lesson_07/README.md +++ b/lesson_07/README.md @@ -18,4 +18,5 @@ Please review the following resources before lecture: This exercise will provide you ample opportunities to practice your understanding of conditional expressions and loops. To complete this assignment, implement the functions in [lesson7.ts][lesson7-file] and in the code file for your assigned homework group, ensure the tests pass, and submit a PR. Remember to use the [Conventional Commits][conventional-commits] spec for your commit messages and pull requests. [lesson7-file]: ./conditionals/src/lesson7.ts -[conventional-commits]: https://www.conventionalcommits.org/en/v1.0.0/ \ No newline at end of file +[conventional-commits]: https://www.conventionalcommits.org/en/v1.0.0/ + diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts index cc44be44c..a757adff3 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -12,9 +12,15 @@ export function compareStrings(a: string, b: string): number { // if it is greater, and 0 if the strings are equal. const distance = computeLexicographicDistance(a, b); - // TODO(you): Finish this method. - - return 0; + if (distance < 0) { + return -1; + } + else if (distance > 0) { + return 1; + } + else { + return 0; + } } /** @@ -24,9 +30,17 @@ export function compareStrings(a: string, b: string): number { * @return The factorial of n. */ export function computeFactorial(n: number): number { - return 0; + if (n ===0 || n===1) { + return 1 + } + else { + return n * computeFactorial(n-1); + } } + + + /** * Returns an array of the first `n` Fibonacci numbers starting from 1. * @@ -35,7 +49,24 @@ export function computeFactorial(n: number): number { */ export function getFirstNFibonacciNumbers(n: number): number[] { return []; -} + if (n===0) { + return[]; + + else if (n=== 1) { + return [1]; + } + else if (n===2) { + return [1,1]; + } + else{ + const fib =getFirstNFibonacciNumbers(n -1); + fib.push(fib[fib.length - 1] + fib [fib.length - 2]); + return fib; + } + } + + } + /** * Finds a value in an array of values. @@ -59,7 +90,19 @@ export function binarySearch( const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array. - // TODO(you): Finish implementing this algorithm + if (values[pivotIndex] === value) { + return pivotIndex; + } else if (values[pivotIndex] > value) { + return binarySearch( values, start, pivotIndex -1, value); + else { binarySearch(values, start, pivotIndex - 1, value)} + return value; + + else { + + return + binarySearch(values, pivotIndex + 1, end, value) + } + } // If values[pivotIndex] is equal to value then return `pivotIndex`. // Else if values[pivotIndex] is greater than the value, then diff --git a/lesson_07/conditionals/src/part_a.ts b/lesson_07/conditionals/src/part_a.ts index 7ad571136..d38d5e48f 100644 --- a/lesson_07/conditionals/src/part_a.ts +++ b/lesson_07/conditionals/src/part_a.ts @@ -5,8 +5,15 @@ * @return True if the age corresponds to a voting age and false otherwise. */ export function canVote(age: number): boolean { - return false; + if (age >= 18) { + return true; + } + + else { + return false; + } } +console.log(canVote(18)) /** * Adds all of the provided values and returns the sum. @@ -15,9 +22,19 @@ export function canVote(age: number): boolean { * @return The sum of all the values. */ export function addNumbers(values: number[]): number { + + + for (let i = 0; i < values.length ; i++) { + + + return values[i]; + } + + return 0; } + /** * Computes the factorial of the given value of `n`. * @@ -25,5 +42,15 @@ export function addNumbers(values: number[]): number { * @return The factorial of n. */ export function computeFactorial(n: number): number { + + if (n <0 ){ + +return 0; + } + + let factorial = 1 + + return 0; } +