Docsity

Scripting languages - homework 5, Schemes and Mind Maps of Javascript programming

Toggle sidebar
bg1
Exercise 5
Task 1
Print Numbers from 5 to 9
Let's implement a while loop that outputs numbers from 5 to 9 to the console.
Task 2
Implement a for loop that outputs the word "Tiger" exactly 5 times.
Task 3
Stop and Skip
Implement a loop that skips even iterations and stops on the 5th iteration. Here
are the instructions:
1. The loop should stop at the 5th iteration.
2. For each iteration, output the iteration number to the console.
3. If the loop skips an iteration, output the word "Skip" to the console.
4. If the loop stops, output the word "Stop" to the console.
Task 4
My Name
Implement a function to output a sentence:
1. Name the function myName.
2. The function should accept one argument, name.
3. The myName function body should contain a console.log() statement that
prints the sentence "My name is {name}".
4. Call the myName function three times with different names.
pf3

Partial preview of the text

Download Scripting languages - homework 5 and more Schemes and Mind Maps Javascript programming in PDF only on Docsity!

Exercise 5 Task 1 Print Numbers from 5 to 9 Let's implement a while loop that outputs numbers from 5 to 9 to the console. Task 2 Implement a for loop that outputs the word "Tiger" exactly 5 times. Task 3 Stop and Skip Implement a loop that skips even iterations and stops on the 5th iteration. Here are the instructions:

  1. The loop should stop at the 5th iteration.
  2. For each iteration, output the iteration number to the console.
  3. If the loop skips an iteration, output the word "Skip" to the console.
  4. If the loop stops, output the word "Stop" to the console. Task 4 My Name Implement a function to output a sentence:
  5. Name the function myName.
  6. The function should accept one argument, name.
  7. The myName function body should contain a console.log() statement that prints the sentence "My name is {name}".
  8. Call the myName function three times with different names.

Task 5 Sum

  1. Implement a function sum that takes 3 arguments (a, b, and c) and returns the sum.
  2. Call this function twice and save the results to the variables sum1 and sum2. Task 6 Create an Object Create a JavaScript object called informationCard representing basic personal information. Inside this object, include a nested object with contact details, such as a home address and phone number. The object should have the following structure: Information card (outer object):
  • First Name (e.g., "???");
  • Last Name (e.g., "???");
  • Age (e.g., ??);
  • Contact Details (nested object) Contact Details (nested object):
  • Home Address (e.g., "???????????");
  • Phone Number (e.g., "???-???-????"); Task 7

Work with Object Methods

You're provided with an object representing a car's details. Your task is to create a method within the object that calculates the car's total price. The car's total cost is calculated by adding the base price and the sum of additional options.

  • Inside the calculateTotalPrice method, use the this keyword to access the car's basePrice.