defc0de
defc0de

Reputation: 25

Strings not being parsed correctly in browser

I have created this JavaScript code and tried running in chrome:

var string1 = "Hello";
var string2 = "Goodbye";

alert(string1);
alert(string2);

string2 = string1;

alert(string1);
alert(string2);

string1 = "Now for something different";

alert(string1);
alert(string2);

as you can see, it's supposed to output 6 alert boxes with different outputs, the problem is I'm only seeing 3 (it ends in the 3rd "Hello" variable).

thanks in advance for your help.

Upvotes: 0

Views: 50

Answers (2)

Josua M C
Josua M C

Reputation: 3158

var string1 = "Hello";
var string2 = "Goodbye";

alert(string1);
alert(string2);

string2 = string1;

alert(string1);
alert(string); // change this line with alert(string2);

string1 = "Now for something different";

alert(string1);
alert(string2);

Upvotes: 0

Matheus Santos
Matheus Santos

Reputation: 680

In the seventh line, correct your alert(string) to alert(string2).

Upvotes: 1

Related Questions