-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Hello world, tadi style | ||
|
||
Here's how to code all the classic 'hello world' examples using a slippy mindset. | ||
|
||
## Hello world | ||
|
||
Easy, just an html file with the following words. | ||
|
||
```html | ||
Hello world! | ||
``` | ||
|
||
<hr> | ||
|
||
Hello world! | ||
|
||
## Button counter | ||
|
||
Another classic. A button that counts upwards. | ||
|
||
```html | ||
<button onclick="handleClick()"> | ||
Count: <span>0</span> | ||
</button> | ||
|
||
<script> | ||
const span = document.querySelector("span") | ||
const handleClick = () => { | ||
span.textContent = parseInt(span.textContent) + 1 | ||
} | ||
</script> | ||
``` | ||
|
||
<hr> | ||
|
||
<button onclick="handleClick()"> | ||
Count: <span>0</span> | ||
</button> | ||
|
||
<script> | ||
const span = document.querySelector("span") | ||
const handleClick = () => { | ||
span.textContent = parseInt(span.textContent) + 1 | ||
} | ||
</script> | ||
|
||
## To-do list | ||
|
||
We can use templates for this one. | ||
|
||
```html | ||
<main> | ||
</main> | ||
<button onclick="handleAddItem()"> | ||
Add item | ||
</button> | ||
|
||
<template> | ||
<p> | ||
<input type="checkbox" /> | ||
<input type="text" /> | ||
<button>Delete</button> | ||
</p> | ||
</template> | ||
|
||
<script> | ||
const main = document.querySelector("main") | ||
const template = document.querySelector("template") | ||
const handleAddItem = () => { | ||
const item = template.content.cloneNode(true) | ||
const delete = item.querySelector("button") | ||
delete.addEventListener("click", () => item.remove()) | ||
main.append(item) | ||
} | ||
</script> | ||
``` | ||
|
||
<hr> | ||
|
||
<main> | ||
</main> | ||
<button onclick="handleAddItem()"> | ||
Add item | ||
</button> | ||
|
||
<template> | ||
<p> | ||
<input type="checkbox" /> | ||
<input type="text" /> | ||
<button>Delete</button> | ||
</p> | ||
</template> | ||
|
||
<script> | ||
const main = document.querySelector("main") | ||
const template = document.querySelector("template") | ||
|
||
const handleAddItem = () => { | ||
const item = template.content.cloneNode(true) | ||
const delete = item.querySelector("button") | ||
delete.addEventListener("click", () => item.remove()) | ||
main.append(item) | ||
} | ||
</script> | ||
|
||
## Any others? | ||
|
||
Do you know any other classic examples I could make? Let me know. My details are on [todepond dot com](/). | ||
|
||
<br> | ||
|
||
Back to the [wikiblogarden](/wikiblogarden). |