This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const message: string = 'goodbye' | |
const count: number = Math.random() | |
const accurate: boolean = count > 0.5 | |
const teacher: 'David Y. Stephenson' = 'David Y. Stephenson' | |
console.log(teacher.length) | |
const a = 1 as number | |
const b: any = 2 | |
const c = a + b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Subject { | |
Js = 'JavaScript', | |
Html = 'Hyper Text Markup Language', | |
Css = 'Cascading Style Sheets', | |
React = 'React' | |
} | |
function describeLearning (subject: Subject) { | |
console.log('Today I learned about:', subject) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Type definition for wand using tuple | |
type Wand = [core: string, length: number, material: string] | |
// Enum for house names | |
enum House { | |
Gryffindor = 'Gryffindor', | |
Slytherin = 'Slytherin' | |
} | |
// Type for character |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Interface for Magical Item | |
interface IMagicalItem { | |
name: string | |
type: string | |
powerLevel: number | |
isRare: boolean | |
} | |
// 2. Class implementing IMagicalItem | |
class MagicalItem implements IMagicalItem { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Question 1: Anonymous Function | |
// Write an anonymous function that takes two numbers as parameters and returns their sum. | |
var add = function (x, y) { | |
return x + y | |
} | |
console.log(add(10, 5)) | |
console.log("\n-------------------------------------------------\n"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Question 1: Anonymous Function | |
// Write an anonymous function that takes two numbers as parameters and returns their sum. | |
var add = function (x, y) { | |
return x + y | |
} | |
console.log(add(10, 5)) | |
console.log("\n-------------------------------------------------\n"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Question 1: Anonymous Function | |
// Write an anonymous function that takes two numbers as parameters and returns their sum. | |
var add = function (x, y) { | |
return x + y | |
} | |
console.log(add(10, 5)) | |
console.log("\n-------------------------------------------------\n"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 6. IIFE Returning a Value | |
// Write an IIFE that returns the square of a number and assign the result to a variable. | |
var result = ((x) => x * x)(5) | |
console.log(result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 7. Arrow functions | |
// Define an arrow function that returns the cube of a number and assign the returned value to a variable. | |
var cube = (x) => x * x * x | |
var result = cube(5) | |
console.log(result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 8. Arrow Function | |
// Write a function to print a right angle triangle of stars. Use arrow function which takes a number as a parameter that represents the number of lines in the triangle. | |
// * | |
// ** | |
// *** | |
var triangle = (x) => { | |
for (var i = 1; i <= x; i++) { | |
var star = '*' |