JavaScript – simple tasks for loops


Goal: write JavaScript code that calculates how much 2^10 is using a loop.

Solution:

varnum=2;
varpower=10;
varresult=1;
var subpower=1
while (subpower<=power){result*=num;subpower++};
document.write(result)

Task: display on five lines 🙂 – on the first one one smiley, on the second – two, etc.

Solution:

var linesNum=5;
var linesNum=5;
varline=””;
var subpower=1;
while (subpower<=linesNum) {line+=”:)”;document.write(line+”<br \/>”);subpower++;}

As a result, we will see:

🙂
:):)
:):):)
:):):):)
:):):):):)


This entry was posted in Javascript (en). Bookmark the permalink.

Leave a Reply

🇬🇧 Attention! Comments with URLs/email are not allowed.
🇷🇺 Комментарии со ссылками/email удаляются автоматически.