Loops, (For, do while, break) Flashcards

1
Q

for

A

for(let i = 0; i < 10; i++ )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

for if/else

A

let spaceShip = prompt(“Qual o nome da sua nave?”)

let charReplace = prompt(“Qual letra você gostaria de substituir?”)

let replacemtechar = prompt(“Por qual letra você gostaria de subtituir?”)

let newSpaceShip = “”

for(let pos = 0; pos < spaceShip.length; pos++){
if(spaceShip[pos] === charReplace){
newSpaceShip += replacemtechar

}else{
    newSpaceShip += spaceShip[pos]
}

}

alert(“O novo nome é: “ + newSpaceShip)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

for, break

A

let names = “Constituição”

for(let i = 0; i < names.length; i++){
if(names[i] === “i”){
break
}
console.log(names[i])
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Do while

A

let a = 50
let b = 5

do{
console.log(“Resultado “ + a)
a += b
}while(a < 100)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

while colocar index

A

let cores = [
“Azul”,
“Verde”,
“Vermelho”,
“Cinza”

]

let index = 0

while (index < cores.length) {
console.log(index + “: “ + cores[index])
index++
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

While numero

A

let a = 1

while(a <= 100) {
console.log(a)
a++
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly