Путин затеял опасную игру в Балтийском море

Нам что, деньги больше тратить некуда?

Learn JavaScript: Loops. The break Keyword

This is an exersise from a Codecademy Javascript-tutorial, that I've made today

Imagine we're looking to adopt a dog. We plan to go to the shelter every day for a year and then give up. But what if we meet our dream dog on day 65? We don't want to keep going to the shelter for the next 300 days just because our original plan was to go for a whole year. In our code, when we want to stop a loop from continuing to execute even though the original stopping condition we wrote for our loop hasn't been met, we can use the keyword break.

The break keyword allows programs to “break” out of the loop from within the loop's block.

Let’s check out the syntax of a break keyword:

for (let i = 0; i < 99; i++){
  if (i > 3) {

console.log('Orange you glad I broke out the loop!');
This is the output for the code:

Orange you glad I broke out the loop!

break statements can be especially helpful when we’re looping through large data structures! With breaks, we can add test conditions besides the stopping condition, and exit the loop when they're met.


1. Log each element from rapperArray in a for loop with the iterator variable rapperArrayIndex.

const rapperArray = ["Lil' Kim", "Jay-Z", "Notorious B.I.G.", "Tupac"];

for (let i = 0; i < rapperArray.length; i++){

2. After the for loop, log the string "And if you don't know, now you know." to the console. Note: since there's a single quote character, ', in our string, we can use double quotes around the string to make sure character prints.

const rapperArray = ["Lil' Kim", "Jay-Z", "Notorious B.I.G.", "Tupac"];

for (let i = 0; i < rapperArray.length; i++){
console.log("And if you don't know, now you know.");

3. Add a break inside your loop's block that breaks out of the loop if the element at the current index in the rapperArray is 'Notorious B.I.G.'.

const rapperArray = ["Lil' Kim", "Jay-Z", "Notorious B.I.G.", "Tupac"];

for (let i = 0; i < rapperArray.length; i++){
  if (rapperArray[i] === 'Notorious B.I.G.'){
console.log("And if you don't know, now you know.");

Learn JavaScript: Loops. Do...While Statements

This is an exersise from a Codecademy course, which I've made today

In some cases, you want a piece of code to run at least once and then loop based on a specific condition after its initial run. This is where the do...while statement comes in.

A do...while statement says to do a task once and then keep doing it until a specified condition is no longer met. The syntax for a do...while statement looks like this:

let countString = '';
let i = 0;

do {
  countString = countString + i;
} while (i < 5);


In this example, the code block makes changes to the countString variable by appending the string form of the i variable to it. First, the code block after the do keyword is executed once. Then the condition is evaluated. If the condition evaluates to true, the block will execute again. The looping stops when the condition evaluates to false.

Note that the while and do...while loop are different! Unlike the while loop, do...while will run at least once whether or not the condition evaluates to true.

const firstMessage = 'I will print!';
const secondMessage = 'I will not print!'; 

// A do while with a stopping condition that evaluates to false
do {
} while (true === false);

// A while loop with a stopping condition that evaluates to false
while (true === false){


1. We'd like a program to simulate part of the cake-baking process. Depending on the recipe, a different number of cups of sugar is required. Create the variable cupsOfSugarNeeded, and assign it a number value of your choosing. The cups of sugar must be added to the batter one at a time. Declare the variable cupsAdded and assign it the value 0.

const cupsOfSugarNeeded = 4;
const cupsAdded = 0;

2. We have a sweet tooth, so we want to add at least one cup of sugar to the batter even if the value of cupsOfSugarNeeded is 0. Create a do...while loop which increments cupsAdded by one while cupsAdded is less than cupsOfSugarNeeded.

let cupsOfSugarNeeded = 4;
let cupsAdded = 0;

do {
 cupsAdded = (cupsAdded + 1); 
} while (cupsAdded < cupsOfSugarNeeded);

How to make a filter using javascript


<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">

<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">

<ul id="myUL">
<li><a href="#">Anton</a></li>
<li><a href="#">Andrey</a></li>

<li><a href="#">Bogdan</a></li>
<li><a href="#">Bill</a></li>
<li><a href="#">Boris</a></li>

<li><a href="#">Calvin</a></li>
<li><a href="#">Christina</a></li>

<script src="script.js"></script>


width: 100%;
font-size: 16px;
padding: 12px 20px 12 px 5 px;
border: 1 px solid #ddd;
margin-bottom: 12px;
list-style: none;
padding: 0;
margin: 0;
#myUL li a {
border: 1px solid #ddd;
margin-top: -1px;
background-color: f6f6f6;
padding: 12px;
text-decoration: none;
font-size: 18px;
color: black;
display: block;
#myUL li a.header{
background-color: #e2e2e2;
cursor: default;
#myUL li a:hover:not(.header){
background-color: #eee;


function myFunction() {
    var input, filter, ul, li, a, i;
    input = document.getElementById("myInput");
    filter = input.value.toUpperCase();
    ul = document.getElementById("myUL");
    li = ul.getElementsByTagName("li");
    for (i = 0; i < li.length; i++) {
        a = li[i].getElementsByTagName("a")[0];
        if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
            li[i].style.display = "";
        } else {
            li[i].style.display = "none";