Skip to content

Guru-Tech-Academy/Week-2-assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Assignment Title: JavaScript Operations and Data Types

Instructions: In this assignment, you will work with various JavaScript operations and data types. Follow the instructions for each task and submit your completed JavaScript code.

Certainly! Here are three JavaScript questions that focus on explicit type conversion:

Question 1: Convert to Number Explicitly (15 points)

Write a JavaScript program that demonstrates explicit type conversion to a number. Perform the following steps:

  1. Declare a variable numberStr and assign it a string value, e.g., "42".
  2. Use explicit type conversion to convert numberStr to a number using the Number() function.
  3. Display the converted number in the console.

Explain in comments how you explicitly converted the string to a number using the Number() function.


Question 2: Convert to String Explicitly (15 points)

Create a JavaScript program that showcases explicit type conversion to a string. Follow these instructions:

  1. Declare a variable num and assign it a numerical value, e.g., 2023.
  2. Use explicit type conversion to convert num to a string using the String() function.
  3. Display the converted string in the console.

Provide comments to explain how you explicitly converted the number to a string using the String() function.


Question 3: Convert to Boolean Explicitly (15 points)

Write a JavaScript program that illustrates explicit type conversion to a boolean. Complete the following steps:

  1. Declare a variable truthyValue and assign it a truthy value, e.g., "Hello".
  2. Declare a variable falsyValue and assign it a falsy value, e.g., 0.
  3. Use explicit type conversion to convert truthyValue to a boolean using the Boolean() function.
  4. Use explicit type conversion to convert falsyValue to a boolean using the Boolean() function.
  5. Display the converted boolean values in the console.

Here are two additional JavaScript questions that focus on working with dates:

Extra questions for practice(not required)

Question 4: Convert JavaScript Dates to Numbers (20 points)

Write a JavaScript program that demonstrates how to convert JavaScript dates to numbers. Perform the following steps:

  1. Declare a variable currentDate and assign it the current date and time using the new Date() constructor.
  2. Use the getTime() method to convert currentDate to a number representing the number of milliseconds since January 1, 1970 (UNIX epoch time).
  3. Display the converted number in the console.

Include comments to explain how you converted the JavaScript date to a number using the getTime() method.


Question 5: Convert JavaScript Dates to Strings (20 points)

Create a JavaScript program that shows how to convert JavaScript dates to strings. Follow these instructions:

  1. Declare a variable eventDate and assign it a specific future date and time using the new Date() constructor.
  2. Use the toLocaleString() method to convert eventDate to a localized date and time string.
  3. Display the converted string in the console.

Provide comments to explain how you converted the JavaScript date to a localized string using the toLocaleString() method.


This addition to the assignment will help students understand how JavaScript handles data type conversions automatically and how they can control conversions manually when working with different data types. Submission Guidelines:

  • Create a single JavaScript file (e.g., assignment.js) to complete all tasks.
  • Include comments to explain your code where necessary.
  • Test your code thoroughly and ensure it works as expected use console.log.
  • Submit your JavaScript file along with any necessary instructions or comments.

Grading Criteria: Your assignment will be graded based on correctness, completeness, code organization, and adherence to the instructions.

Note: Remember to test your code thoroughly and ensure it runs without errors before submitting your assignment.

Important: Fork this repository and commit your assignment code to your forked repository. Submit the URL to Evelyne after you are done with the assignment.


Happy Coding! 😄

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published