36 lines
1001 B
HTML
36 lines
1001 B
HTML
<!DOCTYPE html>
|
|
<html lang="pl">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Lekcja 2 zadanie 3</title>
|
|
<script>
|
|
let text = "ten testowy tekst te słowa testowe testuje: te, ten, Bartek, potencjał, plater. Te."
|
|
</script>
|
|
</head>
|
|
|
|
<body>
|
|
<h1>Podany tekst:</h1>
|
|
<script>
|
|
document.write(text)
|
|
</script>
|
|
|
|
<h2>Szukane słowo:</h2>
|
|
<script>
|
|
let slowo = prompt("Podaj słowo", "te")
|
|
let dozwolone_znaki = [' ', ',', '.']
|
|
|
|
for (let i = 0; i < text.length; i++) {
|
|
if (text.substring(i, i + slowo.length).toLowerCase() == slowo.toLowerCase() && text[i - 1] == ' ' && dozwolone_znaki.includes(text[i + slowo.length])) {
|
|
document.write(`<u>${text.substring(i, i + slowo.length)}</u>`)
|
|
i += slowo.length - 1
|
|
} else {
|
|
document.write(text[i])
|
|
}
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html> |