Saying “Hello World!” in your Language using JavaScript

Almost every programming class or book starts with a “Hello World” script, in which students learn to write a small program that outputs “hello world”.  According to the all-knowing wikipedia, this practice dates back to 1974 and was first used in a book on C.

Although there are programmers all over the world who speak many different languages, for some reason, the script always seems to use English (e.g, “Hello world” instead of “Bonjour monde” or any other language).

Just for fun, we’ve decided to create a little script in JavaScript that let’s you choose in which language you would like to greet the world.

Here’s the function:

function sayHello(language) {
	var arrHellos = {
		"Chinese" : "你好世界",
		"Dutch" : "Hallo wereld",
		"English" : "Hello world",
		"French" : "Bonjour monde",
		"German" : "Hallo Welt",
		"Greek" : "γειά σου κόσμος",
		"Italian" : "Ciao mondo",
		"Japanese" : "こんにちは世界",
		"Korean" : "여보세요 세계",
		"Portuguese" : "Olá mundo",
		"Russian" : "Здравствуй, мир",
		"Spanish" : "Hola mundo"

And here’s a simple HTML form to call the function:

<form method="get" action="javascript:void()">
    <select name="language" id="language">
  <input type="button" onclick="sayHello(this.form.language.options[this.form.language.selectedIndex].value);" value="Say Hello" />

I used for the translations.  If you see any that are wrong, please let me know.  Also, if you know how to say “Hello world” in additional languages, please leave a comment to let me know.

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.