This project contains basic JavaScript examples to demonstrate object manipulation and simple conditional logic. It is designed as an introduction to JavaScript for beginners and covers the following topics:
- Creating and using objects
- Basic validation and conditional statements
- Calculating averages and assigning grades based on scores
To run this project, you need to have Node.js installed. You can download and install it from here.
Once Node.js is installed, you can execute the scripts in your terminal or command prompt.
- Download or clone the project files to your local machine.
- Open a terminal and navigate to the project directory.
- Use the following commands to run each JavaScript file:
- To run
1.js:node 1.js
- To run
2.js:node 2.js
- To run
3.js:node 3.js
- To run
4.js:node 4.js
- To run
This script defines a JavaScript object to represent personal biodata and outputs the contents to the console. The biodata includes:
- Name
- Age
- Hobbies
- Marital status
- List of educational background
- Skills and their proficiency levels
- Interest in coding
You can view and modify this data directly within the script. Example output from this script:
{
name: "Bagus",
age: 25,
hobbies: "reading",
isMarried: false,
schoolList: [...],
skills: [...],
interestInCoding: true
}This script calculates the average of four subject scores (Math, Indonesian, English, and Science) and assigns a grade based on the average:
- A: 90 and above
- B: 80 to 89
- C: 70 to 79
- D: 60 to 69
- E: Below 60
It validates that all scores are present and outputs both the calculated average and the assigned grade.
Example output:
Rata-rata nilai: 82
Grade: BThis script prints an inverted triangle pattern based on a specified number (printSegitiga).
const printSegitiga = 5; // You can change this valueWhen you run this script, it will output the following pattern if printSegitiga is set to 5:
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
This script manages a user's data and updates specific fields like name, email, and hobbies using the spread operator.
The script defines an object data with user details. It then creates an updatedData object with modified fields.
let data = {
id: 1,
name: "Leanne Graham",
username: "Bret",
email: "Sincere@april.biz",
address: {
street: "Kulas Light",
suite: "Apt. 556",
city: "Gwenborough",
zipcode: "92998-3874"
},
phone: "1-770-736-8031 x56442",
website: "hildegard.org",
hobbies: "football"
};The output will be the updated object:
{
id: 1,
name: "nanda",
username: "Bret",
email: "nanda@gmail.com",
address: {
street: "Kulas Light",
suite: "Apt. 556",
city: "Gwenborough",
zipcode: "92998-3874"
},
phone: "1-770-736-8031 x56442",
website: "hildegard.org",
hobbies: "main game"
}
{
street: "Kulas Light",
city: "Gwenborough"
}1.js: Contains the biodata object and displays the information in the console.2.js: Contains the grade calculation logic based on subject scores.3.js: change theprintSegitigavariable to print different patterns.4.js: modify thedataand retrieve data object to use different user information.
- NandaHasnan: Initial script development.