This file contains 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; | |
for (let index in numbers) { | |
total += numbers[index]; | |
} | |
let average = total / numbers.length; | |
console.log("Average:", average); // Output: 86.6 |
This file contains 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; | |
for (let number of numbers) { | |
total += number; | |
} | |
let average = total / numbers.length; | |
console.log("Average:", average); // Output: 86.6 |
This file contains 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 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 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 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 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 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 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 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 |
NewerOlder