Created
April 5, 2025 14:01
-
-
Save sunmeat/e66452905b2aa48f718ed09ae837c19c to your computer and use it in GitHub Desktop.
loops in javascript
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
<!doctype html> | |
<html class="no-js" lang=""> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title></title> | |
<link rel="stylesheet" href="css/style.css"> | |
<link rel="icon" href="/favicon.ico" sizes="any"> | |
<link rel="icon" href="/icon.svg" type="image/svg+xml"> | |
<link rel="apple-touch-icon" href="icon.png"> | |
</head> | |
<body> | |
<script> | |
let userData = { | |
name: "Александр", | |
age: 36, | |
hobbies: ["джаваскрипт", "гитара", "караоке"] | |
}; | |
let count = 0; | |
let maxGreetings = 3; | |
while (count < maxGreetings) { | |
console.log(`Привет, ${userData.name}! (${count + 1}-й раз)`); | |
count++; | |
} | |
let continueGame; | |
do { | |
continueGame = confirm("Хочешь сыграть ещё раз?"); | |
if (continueGame) { | |
alert("Отлично, играем!"); | |
} else { | |
alert("До встречи!"); | |
} | |
} while (continueGame); | |
outerLoop: for (let i = 1; i <= userData.age; i++) { | |
console.log(`Год ${i} из ${userData.age}`); | |
innerLoop: for (let j = 0; j < 3; j++) { | |
console.log(` Месяц ${j + 1} в году ${i}`); | |
if (i === 5 && j === 1) { | |
break outerLoop; | |
} | |
} | |
} | |
for (let key in userData) { | |
console.log(`Свойство: ${key}, Значение: ${userData[key]}`); | |
} | |
for (let hobby of userData.hobbies) { | |
console.log(`Хобби: ${hobby}`); | |
} | |
console.log("Опрос завершён!"); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment