TypeScript-Test/01 Einführung/02 Funktionen/02 Übungen.ipynb

289 lines
8.2 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "4fbccfbc-2e07-4214-a665-4b13afb2723e",
"metadata": {
"editable": false,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"import { assertEquals } from \"jsr:@std/assert\";"
]
},
{
"cell_type": "markdown",
"id": "86eb640a-2c5b-4498-90d7-774984742f45",
"metadata": {
"editable": false,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"# Aufgabe 01.02.1\n",
"Definiere eine Funktion `hallo`, die `'Hallo Welt!'` zurückgibt."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "90e1aef5-ac02-45a6-9f98-3c812ed506f0",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"id": "a6e2ef7a-6785-44b4-be55-55ef733320bd",
"metadata": {
"collapsed": true,
"editable": false,
"jupyter": {
"outputs_hidden": true,
"source_hidden": true
},
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"01.02.1: hallo ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"\n",
"\u001b[0m\u001b[1m\u001b[37m\u001b[41m ERRORS \u001b[0m\n",
"\n",
"01.02.1: hallo \u001b[0m\u001b[38;5;245m=> <anonymous>:1:27\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: hallo is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m2\u001b[0m:\u001b[0m\u001b[33m3\u001b[0m\n",
"\n",
"\u001b[0m\u001b[1m\u001b[37m\u001b[41m FAILURES \u001b[0m\n",
"\n",
"01.02.1: hallo \u001b[0m\u001b[38;5;245m=> <anonymous>:1:27\u001b[0m\n",
"\n",
"\u001b[0m\u001b[31mFAILED\u001b[0m | 0 passed | 1 failed \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n"
]
}
],
"source": [
"Deno.test(\"01.02.1: hallo\", () => {\n",
" assertEquals(typeof hallo, 'function')\n",
"})\n",
"Deno.test(\"01.02.1: hallo\", () => {\n",
" assertEquals(hallo(), 'Hallo Welt!')\n",
"})"
]
},
{
"cell_type": "markdown",
"id": "7b17b7b9-9337-43f9-904b-3d8e11d1d9c3",
"metadata": {
"editable": false,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"# Aufgabe 01.02.2\n",
"Definiere zwei Funktionen. Die erste Funktion `a` soll `'Hallo a!'` zurückgeben. Die zweite Funktion `b` soll `'Hallo b!'` zurückgeben."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "89bda355-b2d5-4e47-9c7e-e711a5663f72",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f084bd1d-cd11-49f7-a0aa-ee33fd7886d3",
"metadata": {
"collapsed": true,
"editable": false,
"jupyter": {
"outputs_hidden": true,
"source_hidden": true
},
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"01.02.2: a ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"01.02.2: b ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"\n",
"\u001b[0m\u001b[1m\u001b[37m\u001b[41m ERRORS \u001b[0m\n",
"\n",
"01.02.2: a \u001b[0m\u001b[38;5;245m=> <anonymous>:1:27\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: a is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m2\u001b[0m:\u001b[0m\u001b[33m3\u001b[0m\n",
"\n",
"01.02.2: b \u001b[0m\u001b[38;5;245m=> <anonymous>:4:6\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: b is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m5\u001b[0m:\u001b[0m\u001b[33m3\u001b[0m\n",
"\n",
"\u001b[0m\u001b[1m\u001b[37m\u001b[41m FAILURES \u001b[0m\n",
"\n",
"01.02.2: a \u001b[0m\u001b[38;5;245m=> <anonymous>:1:27\u001b[0m\n",
"01.02.2: b \u001b[0m\u001b[38;5;245m=> <anonymous>:4:6\u001b[0m\n",
"\n",
"\u001b[0m\u001b[31mFAILED\u001b[0m | 0 passed | 2 failed \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n"
]
}
],
"source": [
"Deno.test(\"01.02.2: a\", () => {\n",
" assertEquals(typeof a, 'function')\n",
"})\n",
"Deno.test(\"01.02.2: b\", () => {\n",
" assertEquals(typeof b, 'function')\n",
"})\n",
"Deno.test(\"01.02.2: a\", () => {\n",
" assertEquals(a(), 'Hallo a!')\n",
"})\n",
"Deno.test(\"01.02.2: b\", () => {\n",
" assertEquals(b(), 'Hallo b!')\n",
"})"
]
},
{
"cell_type": "markdown",
"id": "302df880-f486-4cd5-b0e4-987a122d2b17",
"metadata": {
"editable": false,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"# Aufgabe 01.02.3\n",
"1. Definiere eine Funktion `begruesse`, die den Wert `'Moin!'` zurückgibt.\n",
"2. Deklariere eine Variable `begruessung`. Rufe die Funktion `begruesse` auf und weise der Variablen `begruessung` die Rückgabe dieses Aufrufs zu."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "956109e0-0e4a-416b-94a3-4a6f6c88caf9",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 5,
"id": "d013cd3d-eb31-4a4f-a679-990fb77243c7",
"metadata": {
"collapsed": true,
"editable": false,
"jupyter": {
"outputs_hidden": true,
"source_hidden": true
},
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"01.02.3: begruesse ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"01.02.3: begruessung ... \u001b[0m\u001b[31mFAILED\u001b[0m \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n",
"\n",
"\u001b[0m\u001b[1m\u001b[37m\u001b[41m ERRORS \u001b[0m\n",
"\n",
"01.02.3: begruesse \u001b[0m\u001b[38;5;245m=> <anonymous>:1:27\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: begruesse is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m2\u001b[0m:\u001b[0m\u001b[33m3\u001b[0m\n",
"\n",
"01.02.3: begruessung \u001b[0m\u001b[38;5;245m=> <anonymous>:4:6\u001b[0m\n",
"\u001b[0m\u001b[1m\u001b[31merror\u001b[0m: ReferenceError: begruessung is not defined\n",
" at \u001b[0m\u001b[36m<anonymous>\u001b[0m:\u001b[0m\u001b[33m5\u001b[0m:\u001b[0m\u001b[33m16\u001b[0m\n",
"\n",
"\u001b[0m\u001b[1m\u001b[37m\u001b[41m FAILURES \u001b[0m\n",
"\n",
"01.02.3: begruesse \u001b[0m\u001b[38;5;245m=> <anonymous>:1:27\u001b[0m\n",
"01.02.3: begruessung \u001b[0m\u001b[38;5;245m=> <anonymous>:4:6\u001b[0m\n",
"\n",
"\u001b[0m\u001b[31mFAILED\u001b[0m | 0 passed | 2 failed \u001b[0m\u001b[38;5;245m(0ms)\u001b[0m\n"
]
}
],
"source": [
"Deno.test(\"01.02.3: begruesse\", () => {\n",
" assertEquals(typeof begruesse, 'function')\n",
"})\n",
"Deno.test(\"01.02.3: begruesse\", () => {\n",
" assertEquals(begruesse(), 'Moin!')\n",
"})\n",
"Deno.test(\"01.02.3: begruessung\", () => {\n",
" assertEquals(typeof begruessung, 'string')\n",
"})\n",
"Deno.test(\"01.02.3: begruessung\", () => {\n",
" assertEquals(begruessung, 'Moin!')\n",
"})"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Deno",
"language": "typescript",
"name": "deno"
},
"language_info": {
"codemirror_mode": "typescript",
"file_extension": ".ts",
"mimetype": "text/x.typescript",
"name": "typescript",
"nbconvert_exporter": "script",
"pygments_lexer": "typescript",
"version": "5.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}