Saving and running programs explained | Hello world for programming beginners (Part 2)
text
Crafting Our First Programs
After diving into the Hello World lesson, it's time to take things up a notch. We're going to explore how to make our program a bit more permanent across different environments. Let's look at how to do this using PowerShell, JavaScript, and on a Linux machine.
To achieve our goals, we'll proceed through the following steps:
- Executing Hello World in PowerShell
- Running Hello World in JavaScript
- Executing Hello World on a Linux machine
PowerShell: Our First Stop
Our first stop is PowerShell, a robust command-line interface for Windows platforms. To start, let's open Notepad and type the command:
Write-Host 'Hello World';
To save and execute this PowerShell program, we'll follow these steps:
- Go to File, then Save As in Notepad
- Name the file as HelloWorld.ps1
- Open PowerShell and navigate to the location where the file is saved
- Run:
.\HelloWorld.ps1
JavaScript Programs
Next, we'll shift our focus to JavaScript. Open a new Notepad window and type the following:
<script>
console.log('Hello World');
</script>
Unlike PowerShell, we'll save this code as an HTML file, making it readable by web browsers. After saving, we open the HTML file in a web browser and access the Developer Tools to see the output in the console.
Transitioning to a Linux Machine
Finally, we'll try our hand at a Linux environment. Open a text editor and type:
echo 'Hello World'
To execute this on Linux, we save the file with a .sh
extension and follow these steps:
- Navigate to the location where the
.sh
file is saved - Run:
sh HelloWorld.sh
And there we have it! We've successfully executed Hello World programs in three different environments. If you have any questions, feel free to hit the comments or check out our other tutorials for more insights.
How Code Looks in Movies
Hollywood always tries to make code execution extra dramatic. This is something funny to consider after knowing how code works.
Here is an example to consider:
quiz
resources
updates
Committed by on