BIS601 Program 1

1a) Write a script that Logs “Hello, World!” to the console. Create a script that calculates the sum of two numbers and displays the result in an alert box.
1b) Create an array of 5 cities and perform the following operations: Log the total number of cities. Add a new city at the end. Remove the first city. Find and log the index of a specific city.

Step 1: Install Visual Studio Code (VS Code)

Why Visual Studio Code? VS Code is a free, open-source code editor that provides powerful features like IntelliSense, debugging support, Git integration, and extensions specifically designed for JavaScript and Node.js development.

  • Download VS Code
  • Install VS Code
    Follow the installation instructions for your operating system.
  • Verify Installation
    After installation, open VS Code and check if it’s working. If successful, you should see the VS Code welcome screen.

Step 2: Create Folder and open with vscode

  • Inside the folder create index.html file.
  • After then copy the below code and paste it in that index.html file and save it. Note do one by one both programs.

PROGRAM:

<script>
console.log("Hello World!")
let number1 = 5;
let number2 = 7;
let sum = number1 + number2;
alert("The sum of the numbers is: " + sum);
</script>

Step 3: To run program:

  • Make sure Before running this program live server extension installed in your vscode to run.
  • Right click in the code and open with live server to see the output in alert box.
  • After then open the developer console and see the output of hello world!.

OUTPUT:

Hello, World!
The sum is: 12

PROGRAM:

<script>
let cities = ["New York", "Los Angeles", "Chicago", "Miami", "Houston"];

console.log("Total number of cities: " + cities.length);

cities.push("San Francisco");
console.log("Cities after adding a new one: " + cities);

cities.shift();
console.log("Cities after removing the first one: " + cities);

let cityIndex = cities.indexOf("Miami");
console.log("Index of Miami: " + cityIndex);
</script>

To run program:

  • Same procedure for the program 1.
  • Open developer console to see output.

OUTPUT:

output 1
guest
3 Comments
Inline Feedbacks
View all comments
sachin
sachin
10-02-2025 2:43 PM

Create a script that calculates the sum of two numbers and displays the result in an alert box.
Sir for this question how to display the result in an alert box?

Swapna
Swapna
04-03-2025 3:19 PM

Sir notes are not opening in chrome

3
0
Would love your thoughts, please comment.x
()
x