Freie Scripten und Tutorials erstellt von Roland Geyer       Startseite | Gästebuch

Zeichen zusammenfügen

Beispiel 4 ist jedoch sehr unübersichtlich.

var a = 0;
var b = 0;
var c = 0;
a = window.prompt("Zahlenwert a:");
b = window.prompt("Zahlenwert b:");
a = 1*a;
b = 1*b;
c = a + b;
document.write ("a = ");
document.write (a);
document.write (" ");
document.write ("b = ");
document.write (b);
document.write (" " );
document.write ("c = a + b : " );
document.write (c);


Der Programmiercode kann durch unterschiedliche Verfahren übersichtlicher gestaltet werden.

Wie Sie bereits wissen, können Zeichenketten mit einem + verbunden werden. Dies kann auch innerhalb der Anweisung document.write() geschehen.

Aus:

document.write ("a = ");
document.write (a);
document.write (" ");
document.write ("b = ");
document.write (b);
document.write (" " );
document.write ("c = a + b : " );
document.write (c);

wird:

document.write ("a = " + a + " " + "b = " + b + " c = a + b : " + c);

Daraus folgt

Beispiel 4.4

var a = 0;
var b = 0;
var c = 0;
a = window.prompt("Zahlenwert a:");
b = window.prompt("Zahlenwert b:");
a = 1*a;
b = 1*b;
c = a + b;
document.write ("a = "+a+" "+"b = "+b+" c = a + b : "+c);


Anwendung_4.4

Weitere freie Tutorials: Rhetorik & Kommunikation Typografie & Layout Bildbearbeitung mit Photoshop oder GIMP Vektorgrafik mit Illustrator, FreeHand, Corel Draw oder Inkscape Layout mit Indesign oder Scribus Druckvorstufe GoLive Html JavaScript Flash & ActionScript Director & Lingo Assembler DOS Java objektorientiert Perl Word Excel Access PowerPoint Outlook Betriebssystem