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
let numbers: number[] = [85, 90, 78, 92, 88]; | |
let total = 0; | |
let count = numbers.length; | |
numbers.forEach((number) => { | |
total += number; | |
}); | |
let average = total / count; | |
console.log("Average:", average); //Output is 86.6 |
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
let numbers: number[] = [85, 90, 78, 92, 88]; | |
let total = 0; | |
let count = numbers.length; | |
for (let i = 0; i < count; i++) { | |
total += numbers[i]; | |
} | |
let average = total / count; | |
console.log("Average:", average); //Output is 86.6 |
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
let numbers: number[] = [85, 90, 78, 92, 88]; | |
let total = 0; | |
let count = numbers.length; | |
let i = 0; | |
do { | |
total += numbers[i]; | |
i++; | |
} while (i < count); |
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
let numbers: number[] = [85, 90, 78, 92, 88]; | |
let total = 0; | |
let count = numbers.length; | |
let i = 0; | |
while (i < count) { | |
total += numbers[i]; | |
i++; | |
} |
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
let scores: numbers[] = [55, 82, 21]; |
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
let sports: string[] = ['Volleyball', 'Football', 'Basketball', 'Soccer']; | |
sports[1] = 'Tennis'; | |
// Replaces 'Football' with 'Tennis' | |
console.log(sports); | |
// Output: ['Volleyball', 'Tennis', 'Basketball', 'Soccer'] |
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
let sports: string[] = ['Volleyball', 'Football', 'Basketball', 'Soccer']; |
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
let notification: NotificationSender; | |
notification = new EmailSender("Project Update", "[email protected]"); | |
notification.send(); // Output: Sending email: 'Project Update' to [email protected] | |
notification = new SMSSender("Meeting at 3 PM", "123456789"); | |
notification.send(); // Output: Sending SMS: 'Meeting at 3 PM' to 123456789 |
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
class SMSSender extends NotificationSender { | |
send(): void { | |
console.log(`Sending SMS: '${this.message}' to ${this.recipient}`); | |
} | |
} | |
class EmailSender extends NotificationSender { | |
send(): void { | |
console.log(`Sending email: '${this.message}' to ${this.recipient}`); | |
} |
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
class EmailSender extends NotificationSender { | |
sendEmail(): void { | |
console.log(`Sending email: '${this.message}' to ${this.recipient}`); | |
} | |
} |