lehrkraefte:blc:informatik:ffprg1-2021:js:helloworld

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
lehrkraefte:blc:informatik:ffprg1-2021:js:helloworld [2021/04/29 05:13] Ivo Blöchligerlehrkraefte:blc:informatik:ffprg1-2021:js:helloworld [2021/04/29 05:15] (current) Ivo Blöchliger
Line 1: Line 1:
 +====== Hello World ======
 +  * Legen Sie einen Ordner ''javascript'' und darin einen Ordner ''hello'' an. Speichern Sie dann folgende beide Dateien im Ordner ''hello''.
 +  * Öffnen Sie die Datei ''hello.html'' in einem Browser, und aktivieren die mit F12 die Entwicklertools und dort die Konsole.
 +<code html hello.html>
 +<!DOCTYPE html>
 +<html>
 +  <head>
 +    <meta charset="UTF-8" />
 +    <title>Hello World</title>
 + <script src="hello.js"></script>
 +  </head>
 +  <body>
 +    <h1>Hello World</h1>
 + <p>Beim Klicken wird Funktion hello aufgerufen.
 + <p>Die Ausgabe erfolgt auf der Konsole (F12, Console)
 + <p><button onclick="hello()">Klick mich</button>
 +  </body>
 +</html>
 +</code>
 +
 +<code javascript hello.js>
 +// Globale Funktion hello definieren
 +// Code zwischen { und }
 +
 +function hello() {
 + // Auf der Konsole ausgeben (Browser: F12 -> Console)
 + console.log("Hello world!");  // Achtung: Strichpunkt nach jeder Anweisung!
 +}
 +</code>
 +
 +