• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net

JavaScript "Hello" randomizer


It gets better.
Hello FWS!

It's been a good few years since I've done much coding of anything. I've started again since I've done bits here and there in work and I'm trying to re-do my personal website. The thing I'm having an issue with is having a area of my site display different languages of "Hello", selecting them from an array. The code itself works, but how its displaying on the page isn't.

var HelloWorld = new Array()

	HelloWorld[1] = 'Hello',
	HelloWorld[2] = 'Hallo',
	HelloWorld[3] = 'Përshëndetje',
	HelloWorld[4] = 'مرحبا',
	HelloWorld[5] = 'Բարեւ Ձեզ',
	HelloWorld[6] = 'Salam',
	HelloWorld[7] = 'Kaixo',
	HelloWorld[8] = 'Прывітанне',
	HelloWorld[9] = 'Здравейте',
	HelloWorld[10] = 'Hola',
	HelloWorld[11] = '你好',
	HelloWorld[12] = 'Bok',
	HelloWorld[13] = 'Ahoj',
	HelloWorld[14] = 'Hej',
	HelloWorld[15] = 'Saluton',
	HelloWorld[16] = 'Tere',
	HelloWorld[17] = 'Hei',
	HelloWorld[18] = 'Bonjour',
	HelloWorld[19] = 'Ola',
	HelloWorld[20] = 'გამარჯობა',
	HelloWorld[21] = 'Γεια σας',
	HelloWorld[22] = 'હેલો',
	HelloWorld[23] = 'Alo',
	HelloWorld[24] = 'שלום',
	HelloWorld[25] = 'Helló',
	HelloWorld[26] = 'नमस्ते',
	HelloWorld[27] = 'Dia duit',
	HelloWorld[28] = 'Ciao',
	HelloWorld[29] = 'もしもし',
	HelloWorld[30] = '안녕하세요.',
	HelloWorld[31] = 'Salve',
	HelloWorld[32] = 'Sveiki',
	HelloWorld[33] = 'Здраво',
	HelloWorld[34] = 'سلام',
	HelloWorld[35] = 'Olá',
	HelloWorld[36] = 'привет',
	HelloWorld[37] = 'Pozdravljeni',
	HelloWorld[38] = '¡Hola',
	HelloWorld[39] = 'Wapendwa',
	HelloWorld[40] = 'Hallå',
	HelloWorld[41] = 'வணக்கம்',
	HelloWorld[42] = 'สวัสดี',
	HelloWorld[43] = 'Merhaba',
	HelloWorld[44] = 'Привіт',
	HelloWorld[45] = 'خوش',
	HelloWorld[46] = 'Chào',
	HelloWorld[47] = 'Helo',
	HelloWorld[48] = 'העלא';
	var EchoWorld = HelloWorld[Math.floor(Math.random() * HelloWorld.length)];


So that's the code, used Google for the translations. If you check the screenshot, you can see its loading another random string from the array and displaying it at the very top of the page. When I first tested it with only about 5 strings it worked fine, displaying only on the menubar (and not the top) but it was showing undefined every once in a while. Adding over 10 or so strings removes that but now it is constantly displaying twice.

Any ideas why it's doing this? Or a cleaner better way to do it (like Flickr has?)


Jay Street
maybe put your entire page code. there has to be something that is wrong somewhere else. I have it running here, and it works fine.


It gets better.
edit: Nevermind, changing from JS to PHP didn't stop the weird behaviour, after a few refreshes it began again. It appears to show at the top of the page if I include the code within the <head> element. If I just add the entire code to where I want it displayed, it works fine. Here's the PHP version anyway, the JS version still sometimes displays undefined.


	$HelloWorld = array(
		'Hello', 'Hallo', 'Përshëndetje', 'مرحبا','Բարեւ Ձեզ','Salam', 'Kaixo',
		'Прывітанне', 'Здравейте', 'Hola', 'Bok', 'Ahoj', 'Hej', 'Saluton', 'Tere',
		'Hei', 'Bonjour', 'Ola', 'გამარჯობა', 'Γεια σας', 'હેલો', 'Alo', 'Helló', 'नमस्ते',
		'Dia duit', 'Ciao', '안녕하세요.', 'Salve', 'Sveiki', 'Здраво', 'سلام', 'Olá', 'привет',
		'Pozdravljeni', '¡Hola', 'Wapendwa', 'Hallå', 'வணக்கம்', 'สวัสดี', 'Merhaba', 'Привіт',
		'خوش', 'Chào', 'Helo', 'העלא'
	echo $HelloWorld[array_rand($HelloWorld, 1)];
Last edited:


It gets better.
Having a new problem, it started randomly, and now I'm completely stumped and what is causing it.

Problem is, I'm including a header and a footer from PHP files into each page to make it easier for edits. I have one page that is acting as my blog. This consists of an include for the header, then an iFrame, then an include for the footer (easy setup for now with the iFrame). The headers/footers load fine on every other page. But for some reason the footer on the blog page (that was displaying fine) no longer is. I've not changed ANY code that should affect this.

You can see the problem yourself here: http://www.javakrypt.com/new (showing it works) and then http://www.javakrypt.com/new/blog (where it doesn't).

What is causing this?


Super Moderator#1
I see a footer. Did you fix it? I'm getting this error in console: @font-face failed OpenType embedding permission check. Permission must be Installable.


It gets better.
Nevermind, fixed it. I'm just an idiot. Overlooked an unclosed div, even after re-checking it!
Last edited: