This commit is contained in:
72
01_grundlagen/unterricht/tag03/02_variablendeklaration.html
Normal file
72
01_grundlagen/unterricht/tag03/02_variablendeklaration.html
Normal file
@@ -0,0 +1,72 @@
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Variablen in JS</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="container py-5">
|
||||
<h1>Variablen in JS</h1>
|
||||
</div>
|
||||
</main>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
// Variablendeklaration
|
||||
let username;
|
||||
|
||||
console.log('username:', username); // => undefined
|
||||
|
||||
username = 'Oswine';
|
||||
|
||||
console.log('username:', username); // => 'Oswine'
|
||||
|
||||
// Variablendefinition
|
||||
let firstName = 'Max';
|
||||
|
||||
console.log('firstName:', firstName); // => 'Max'
|
||||
|
||||
// let firstName = 'Jane'; // Deklaration mit identischem Bezeichner ist nicht möglich
|
||||
let firstname = 'Max2';
|
||||
|
||||
console.log('firstname:', firstname); // => 'Max2'
|
||||
|
||||
// Variablendefinitionen
|
||||
let age = 40;
|
||||
let toggle = true;
|
||||
|
||||
// lowerCamelCase - Schreibweise
|
||||
let myAddress = 'Entenhausenstr. 1';
|
||||
let myCounter = 1;
|
||||
let questionOne = 'Wie alt bist Du?';
|
||||
let question2 = 'Wie groß bist Du?';
|
||||
|
||||
myCounter = myCounter + 1;
|
||||
console.log('myCounter: ', myCounter); // => 2;
|
||||
|
||||
toggle = !toggle; // => !(true) => false
|
||||
console.log('toggle: ', toggle); // => false;
|
||||
|
||||
myCounter = 'Guter Counter';
|
||||
|
||||
console.log('myCounter:', myCounter); // => 'Guter Counter' <- eigentlich wird eine Zahl (number) erwartet.
|
||||
|
||||
// prefer-const
|
||||
// https://github.com/airbnb/javascript#references
|
||||
|
||||
const myRole = 'admin';
|
||||
|
||||
// myRole = 'guest'; // Uncaught TypeError: Assignment to constant variable.
|
||||
const myUrl = 'https://gfn.de';
|
||||
const html = '<strong>HTML</strong>';
|
||||
|
||||
// Konfigurationsvariable (SCREAMING_SNAKE_CASE)
|
||||
const HOST = '127.0.0.1';
|
||||
const PORT = 3000;
|
||||
const DEFAULT_LANG = 'EN-en';
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
30
01_grundlagen/unterricht/tag03/03_prompt.html
Normal file
30
01_grundlagen/unterricht/tag03/03_prompt.html
Normal file
@@ -0,0 +1,30 @@
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Prompt - Dialogfenster mit Eingabetextfeld in JS</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="container py-5">
|
||||
<h1>Prompt - Dialogfenster mit Eingabetextfeld in JS</h1>
|
||||
<div class="output alert alert-secondary my-3"></div>
|
||||
</div>
|
||||
</main>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
const outputEl = document.querySelector('.output');
|
||||
|
||||
// prefer-const
|
||||
const username = prompt('Please let me know your name!');
|
||||
|
||||
console.log(username);
|
||||
|
||||
// username = 'changedName'; // Uncaught TypeError: Assignment to constant variable.
|
||||
outputEl.textContent = `Your username is ${username}`;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user