<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://progzoo.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Carlos</id>
	<title>ProgZoo - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://progzoo.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Carlos"/>
	<link rel="alternate" type="text/html" href="https://progzoo.net/Special:Contributions/Carlos"/>
	<updated>2026-06-10T06:35:02Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://progzoo.net/index.php?title=DOM_Working_with_data&amp;diff=973</id>
		<title>DOM Working with data</title>
		<link rel="alternate" type="text/html" href="https://progzoo.net/index.php?title=DOM_Working_with_data&amp;diff=973"/>
		<updated>2022-01-18T08:58:04Z</updated>

		<summary type="html">&lt;p&gt;Carlos: /* Format numbers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;pre id=&#039;shellbody&#039; data-qtp=&#039;fetch&#039;&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
== Get the name from the number ==&lt;br /&gt;
*You can obtain data from the server using a fetch call.&lt;br /&gt;
*In these examples you will be getting data from https://progzoo.net/worldl.json this is a list of 195 countries in json format&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
* The program snippet shows the name of country 42.&lt;br /&gt;
* Change it so it shows the name of country 50.&lt;br /&gt;
* See if you can find your country.&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[42];&lt;br /&gt;
     document.body.innerHTML = tgt.name;&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[50];&lt;br /&gt;
     document.body.innerHTML = tgt.name;&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each country has a bunch of data associated, for example:&lt;br /&gt;
 area: 330803&lt;br /&gt;
 capital: &amp;quot;Kuala Lumpur&amp;quot;&lt;br /&gt;
 continent: &amp;quot;Asia&amp;quot;&lt;br /&gt;
 flag: &amp;quot;//upload.wikimedia.org/wikipedia/commons/6/66/Flag_of_Malaysia.svg&amp;quot;&lt;br /&gt;
 gdp: 304726000000&lt;br /&gt;
 id: 102&lt;br /&gt;
 name: &amp;quot;Malaysia&amp;quot;&lt;br /&gt;
 population: 30177000&lt;br /&gt;
 tld: &amp;quot;.my&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Show the population ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=imper&amp;gt;Alter your code so that the output matches the model answer.&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[102];&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.name}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[102];&lt;br /&gt;
     document.body.innerHTML =&lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.name}, ${tgt.population}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Include image ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;div class=imper&amp;gt;Include three div elements and an img for country 151. Use &amp;lt;code&amp;gt;style=&#039;width:100px;&#039;&amp;lt;/code&amp;gt; for the img&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[151];&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.name}, ${tgt.capital}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[151];&lt;br /&gt;
     document.body.innerHTML = `&lt;br /&gt;
&amp;lt;div&amp;gt;Name: ${tgt.name}&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div&amp;gt;Capital: ${tgt.capital}&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div&amp;gt;Population: ${tgt.population}&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;img src=&#039;${tgt.flag}&#039; style=&#039;width:100px&#039;/&amp;gt;&lt;br /&gt;
`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Output in a table ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[172];&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.name}, ${tgt.capital}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[172];&lt;br /&gt;
     document.body.innerHTML = `&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.name}&amp;lt;/td&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Continent&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.continent}&amp;lt;/td&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Capital&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.capital}&amp;lt;/td&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Population&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.population}&amp;lt;/td&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Format numbers ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;div class=&#039;imper&#039;&amp;gt;For country 184. Use .toLocaleString() to format numbers better. Show the GDP in billions, include $ symbol as GDP is given in US dollars&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[184];&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.population.toLocaleString()}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[184];&lt;br /&gt;
     document.body.innerHTML =        `&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.name}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Continent&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.continent}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Capital&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.capital}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Population&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.population.toLocaleString(&#039;en&#039;)}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;GDP&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.gdp.toLocaleString(&#039;en&#039;)} billion&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Working with lists ==&lt;br /&gt;
In the following questions you must look at the list of the countries to work out the answer.&lt;br /&gt;
== Biggest Country in the World ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;div class=&#039;imper&#039;&amp;gt;Show the name of the country with the largest population.&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let biggest = 0;&lt;br /&gt;
     for(let i = 0; i&amp;lt;r.length; i++){&lt;br /&gt;
       if (r[i].area &amp;gt; r[biggest].area){&lt;br /&gt;
         biggest = i;&lt;br /&gt;
       }&lt;br /&gt;
     }&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${r[biggest].name}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
   });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let biggest = 0;&lt;br /&gt;
     for(let i = 0; i&amp;lt;r.length; i++){&lt;br /&gt;
       if (r[i].population &amp;gt; r[biggest].population){&lt;br /&gt;
         biggest = i;&lt;br /&gt;
       }&lt;br /&gt;
     }&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${r[biggest].name}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
   });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Total population ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;div class=&#039;imper&#039;&amp;gt;Show the total population of the world.&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let acc = 0;&lt;br /&gt;
     for(let i = 0; i&amp;lt;r.length; i++){&lt;br /&gt;
       acc += r[i].population&lt;br /&gt;
     }&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${acc}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
   });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
== Countries bigger than 1000000 ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;div class=&#039;imper&#039;&amp;gt;Show list of countries with an area of more than 1 million square kilometers.&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     document.body.innerHTML =&lt;br /&gt;
       r.filter(r=&amp;gt;r.area&amp;gt;1000000)&lt;br /&gt;
        .map(r=&amp;gt;`&amp;lt;div&amp;gt;${r.name}&amp;lt;/div&amp;gt;`)&lt;br /&gt;
        .join(&#039;&#039;);&lt;br /&gt;
   });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Countries in Europe ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;div class=&#039;imper&#039;&amp;gt;Show list of countries where the continent is Europe.&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     document.body.innerHTML =&lt;br /&gt;
       r.filter(r=&amp;gt;r.continent === &#039;Europe&#039;)&lt;br /&gt;
        .map(r=&amp;gt;`&amp;lt;div&amp;gt;${r.name}&amp;lt;/div&amp;gt;`)&lt;br /&gt;
        .join(&#039;&#039;);&lt;br /&gt;
   });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlos</name></author>
	</entry>
	<entry>
		<id>https://progzoo.net/index.php?title=DOM_Working_with_data&amp;diff=972</id>
		<title>DOM Working with data</title>
		<link rel="alternate" type="text/html" href="https://progzoo.net/index.php?title=DOM_Working_with_data&amp;diff=972"/>
		<updated>2022-01-18T08:56:17Z</updated>

		<summary type="html">&lt;p&gt;Carlos: /* Format numbers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;pre id=&#039;shellbody&#039; data-qtp=&#039;fetch&#039;&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
== Get the name from the number ==&lt;br /&gt;
*You can obtain data from the server using a fetch call.&lt;br /&gt;
*In these examples you will be getting data from https://progzoo.net/worldl.json this is a list of 195 countries in json format&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
* The program snippet shows the name of country 42.&lt;br /&gt;
* Change it so it shows the name of country 50.&lt;br /&gt;
* See if you can find your country.&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[42];&lt;br /&gt;
     document.body.innerHTML = tgt.name;&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[50];&lt;br /&gt;
     document.body.innerHTML = tgt.name;&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each country has a bunch of data associated, for example:&lt;br /&gt;
 area: 330803&lt;br /&gt;
 capital: &amp;quot;Kuala Lumpur&amp;quot;&lt;br /&gt;
 continent: &amp;quot;Asia&amp;quot;&lt;br /&gt;
 flag: &amp;quot;//upload.wikimedia.org/wikipedia/commons/6/66/Flag_of_Malaysia.svg&amp;quot;&lt;br /&gt;
 gdp: 304726000000&lt;br /&gt;
 id: 102&lt;br /&gt;
 name: &amp;quot;Malaysia&amp;quot;&lt;br /&gt;
 population: 30177000&lt;br /&gt;
 tld: &amp;quot;.my&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Show the population ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=imper&amp;gt;Alter your code so that the output matches the model answer.&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[102];&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.name}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[102];&lt;br /&gt;
     document.body.innerHTML =&lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.name}, ${tgt.population}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Include image ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;div class=imper&amp;gt;Include three div elements and an img for country 151. Use &amp;lt;code&amp;gt;style=&#039;width:100px;&#039;&amp;lt;/code&amp;gt; for the img&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[151];&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.name}, ${tgt.capital}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[151];&lt;br /&gt;
     document.body.innerHTML = `&lt;br /&gt;
&amp;lt;div&amp;gt;Name: ${tgt.name}&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div&amp;gt;Capital: ${tgt.capital}&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div&amp;gt;Population: ${tgt.population}&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;img src=&#039;${tgt.flag}&#039; style=&#039;width:100px&#039;/&amp;gt;&lt;br /&gt;
`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Output in a table ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[172];&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.name}, ${tgt.capital}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[172];&lt;br /&gt;
     document.body.innerHTML = `&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.name}&amp;lt;/td&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Continent&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.continent}&amp;lt;/td&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Capital&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.capital}&amp;lt;/td&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Population&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.population}&amp;lt;/td&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Format numbers ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;div class=&#039;imper&#039;&amp;gt;For country 184. Use .toLocaleString() to format numbers better. Show the GDP in billions, include $ symbol as GDP is given in US dollars&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[184];&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.population.toLocaleString()}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[184];&lt;br /&gt;
     document.body.innerHTML =        `&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.name}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Continent&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.continent}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Capital&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.capital}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Population&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.population.toLocaleString(&#039;en&#039;)}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;GDP&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${(tgt.gdp/1e9).toLocaleString(&#039;en&#039;)} billion&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Working with lists ==&lt;br /&gt;
In the following questions you must look at the list of the countries to work out the answer.&lt;br /&gt;
== Biggest Country in the World ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;div class=&#039;imper&#039;&amp;gt;Show the name of the country with the largest population.&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let biggest = 0;&lt;br /&gt;
     for(let i = 0; i&amp;lt;r.length; i++){&lt;br /&gt;
       if (r[i].area &amp;gt; r[biggest].area){&lt;br /&gt;
         biggest = i;&lt;br /&gt;
       }&lt;br /&gt;
     }&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${r[biggest].name}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
   });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let biggest = 0;&lt;br /&gt;
     for(let i = 0; i&amp;lt;r.length; i++){&lt;br /&gt;
       if (r[i].population &amp;gt; r[biggest].population){&lt;br /&gt;
         biggest = i;&lt;br /&gt;
       }&lt;br /&gt;
     }&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${r[biggest].name}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
   });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Total population ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;div class=&#039;imper&#039;&amp;gt;Show the total population of the world.&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let acc = 0;&lt;br /&gt;
     for(let i = 0; i&amp;lt;r.length; i++){&lt;br /&gt;
       acc += r[i].population&lt;br /&gt;
     }&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${acc}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
   });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
== Countries bigger than 1000000 ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;div class=&#039;imper&#039;&amp;gt;Show list of countries with an area of more than 1 million square kilometers.&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     document.body.innerHTML =&lt;br /&gt;
       r.filter(r=&amp;gt;r.area&amp;gt;1000000)&lt;br /&gt;
        .map(r=&amp;gt;`&amp;lt;div&amp;gt;${r.name}&amp;lt;/div&amp;gt;`)&lt;br /&gt;
        .join(&#039;&#039;);&lt;br /&gt;
   });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Countries in Europe ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;div class=&#039;imper&#039;&amp;gt;Show list of countries where the continent is Europe.&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     document.body.innerHTML =&lt;br /&gt;
       r.filter(r=&amp;gt;r.continent === &#039;Europe&#039;)&lt;br /&gt;
        .map(r=&amp;gt;`&amp;lt;div&amp;gt;${r.name}&amp;lt;/div&amp;gt;`)&lt;br /&gt;
        .join(&#039;&#039;);&lt;br /&gt;
   });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlos</name></author>
	</entry>
	<entry>
		<id>https://progzoo.net/index.php?title=DOM_Working_with_data&amp;diff=721</id>
		<title>DOM Working with data</title>
		<link rel="alternate" type="text/html" href="https://progzoo.net/index.php?title=DOM_Working_with_data&amp;diff=721"/>
		<updated>2021-09-14T06:26:10Z</updated>

		<summary type="html">&lt;p&gt;Carlos: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;pre id=&#039;shellbody&#039; data-qtp=&#039;fetch&#039;&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
== Get the name from the number ==&lt;br /&gt;
*You can obtain data from the server using a fetch call.&lt;br /&gt;
*In these examples you will be getting data from https://progzoo.net/worldl.json this is a list of 195 countries in json format&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
* The program snippet shows the name of country 42.&lt;br /&gt;
* Change it so it shows the name of country 50.&lt;br /&gt;
* See if you can find your country.&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[42];&lt;br /&gt;
     document.body.innerHTML = tgt.name;&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[50];&lt;br /&gt;
     document.body.innerHTML = tgt.name;&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each country has a bunch of data associated, for example:&lt;br /&gt;
 area: 330803&lt;br /&gt;
 capital: &amp;quot;Kuala Lumpur&amp;quot;&lt;br /&gt;
 continent: &amp;quot;Asia&amp;quot;&lt;br /&gt;
 flag: &amp;quot;//upload.wikimedia.org/wikipedia/commons/6/66/Flag_of_Malaysia.svg&amp;quot;&lt;br /&gt;
 gdp: 304726000000&lt;br /&gt;
 id: 102&lt;br /&gt;
 name: &amp;quot;Malaysia&amp;quot;&lt;br /&gt;
 population: 30177000&lt;br /&gt;
 tld: &amp;quot;.my&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Show the population ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=imper&amp;gt;Alter your code so that the output matches the model answer.&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[102];&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.name}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[102];&lt;br /&gt;
     document.body.innerHTML =&lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.name}, ${tgt.population}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Include image ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;div class=imper&amp;gt;Include three div elements and an img for country 151. Use &amp;lt;code&amp;gt;style=&#039;width:100px;&#039;&amp;lt;/code&amp;gt; for the img&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[151];&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.name}, ${tgt.capital}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[151];&lt;br /&gt;
     document.body.innerHTML = `&lt;br /&gt;
&amp;lt;div&amp;gt;Name: ${tgt.name}&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div&amp;gt;Capital: ${tgt.capital}&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div&amp;gt;Population: ${tgt.population}&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;img src=&#039;${tgt.flag}&#039; style=&#039;width:100px&#039;/&amp;gt;&lt;br /&gt;
`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Output in a table ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[172];&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.name}, ${tgt.capital}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[172];&lt;br /&gt;
     document.body.innerHTML = `&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.name}&amp;lt;/td&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Continent&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.continent}&amp;lt;/td&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Capital&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.capital}&amp;lt;/td&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Population&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.population}&amp;lt;/td&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Format numbers ==&lt;br /&gt;
&amp;lt;div class=qu&amp;gt;&lt;br /&gt;
&amp;lt;div class=&#039;imper&#039;&amp;gt;For country 184. Use .toLocaleString() to format numbers better. Show the GDP in billions, include $ symbol as GDP is given in US dollars&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[184];&lt;br /&gt;
     document.body.innerHTML = &lt;br /&gt;
       `&amp;lt;div&amp;gt;${tgt.population.toLocaleString()}&amp;lt;/div&amp;gt;`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
fetch(&#039;/worldl.json&#039;)&lt;br /&gt;
  .then((r)=&amp;gt;r.json())&lt;br /&gt;
  .then((r)=&amp;gt;{&lt;br /&gt;
     let tgt = r[184];&lt;br /&gt;
     document.body.innerHTML =        `&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.name}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Continent&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.continent}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Capital&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.capital}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Population&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;${tgt.population.toLocaleString(&#039;en&#039;)}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;GDP&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;$${(tgt.gdp/1e9).toLocaleString(&#039;en&#039;)} billion&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
`;&lt;br /&gt;
     });&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlos</name></author>
	</entry>
	<entry>
		<id>https://progzoo.net/index.php?title=Flags_with_Lines&amp;diff=720</id>
		<title>Flags with Lines</title>
		<link rel="alternate" type="text/html" href="https://progzoo.net/index.php?title=Flags_with_Lines&amp;diff=720"/>
		<updated>2021-09-13T08:20:18Z</updated>

		<summary type="html">&lt;p&gt;Carlos: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;pre id=&#039;shellbody&#039; data-qtp=&#039;canvas&#039;&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Get on with the programming, don&#039;t pause to look at this worked example: [[Road Sign Square]]&lt;br /&gt;
==England==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=qu data-height=&amp;quot;90&amp;quot; data-width=&amp;quot;150&amp;quot;&amp;gt;&lt;br /&gt;
The English flag is the cross of St. George. This is a red cross on a white&lt;br /&gt;
background .&lt;br /&gt;
*The line thickness should be 18. &lt;br /&gt;
[[Image:flagengland.png]]&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;white&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,150,90);&lt;br /&gt;
  ctx.strokeStyle = &#039;red&#039;;&lt;br /&gt;
  ctx.lineWidth = 18;&lt;br /&gt;
  ctx.moveTo(0,45);&lt;br /&gt;
  ctx.lineTo(150,45);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;white&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,150,90);&lt;br /&gt;
  ctx.strokeStyle = &#039;red&#039;;&lt;br /&gt;
  ctx.lineWidth = 18;&lt;br /&gt;
  ctx.moveTo(0,45);&lt;br /&gt;
  ctx.lineTo(150,45);&lt;br /&gt;
  ctx.moveTo(75,0);&lt;br /&gt;
  ctx.lineTo(75,90);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Scotland==&lt;br /&gt;
&amp;lt;div class=qu data-height=&amp;quot;90&amp;quot; data-width=&amp;quot;150&amp;quot; data-cols=&#039;40&#039;&amp;gt;&lt;br /&gt;
The cross of St. Andrew shows diagonal lines on a blue background.&amp;lt;br/&amp;gt;&lt;br /&gt;
*Complete the flag by drawing the other diagonal  line.&lt;br /&gt;
*The white lines should be slightly thicker - try 18.&lt;br /&gt;
[[Image:flagscotland.png]]&lt;br /&gt;
&amp;lt;pre class=usr lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;white&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,150,90);&lt;br /&gt;
  ctx.strokeStyle = &#039;red&#039;;&lt;br /&gt;
  ctx.lineWidth = 18;&lt;br /&gt;
  ctx.moveTo(0,0);&lt;br /&gt;
  ctx.lineTo(150,90);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;blue&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,150,90);&lt;br /&gt;
  ctx.strokeStyle = &#039;white&#039;;&lt;br /&gt;
  ctx.lineWidth = 18;&lt;br /&gt;
  ctx.moveTo(0,0);&lt;br /&gt;
  ctx.lineTo(150,90);&lt;br /&gt;
  ctx.moveTo(0,90);&lt;br /&gt;
  ctx.lineTo(150,0);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Botswana==&lt;br /&gt;
&amp;lt;div class=qu data-width=&amp;quot;150&amp;quot; data-height=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
The flag of Botswana has a black stripe on a white stripe on a blue background.&lt;br /&gt;
&lt;br /&gt;
[[Image:flagbotswana.png|border]]&lt;br /&gt;
*The flag is 150 by 100&lt;br /&gt;
*The white stripe behind the black one has width 30&lt;br /&gt;
*The black stripe has width 20&lt;br /&gt;
*The pale blue has rgb: &#039;#6EB6ED&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;#6EB6ED&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,150,100);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;#6EB6ED&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,150,100);&lt;br /&gt;
  ctx.strokeStyle = &#039;white&#039;;&lt;br /&gt;
  ctx.lineWidth = 30;&lt;br /&gt;
  ctx.moveTo(0,50);&lt;br /&gt;
  ctx.lineTo(150,50);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
  ctx.strokeStyle = &#039;black&#039;;&lt;br /&gt;
  ctx.lineWidth = 20;&lt;br /&gt;
  ctx.moveTo(0,50);&lt;br /&gt;
  ctx.lineTo(150,50);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Iceland==&lt;br /&gt;
&amp;lt;div class=qu data-width=&amp;quot;125&amp;quot; data-height=&amp;quot;90&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image:flagiceland.png|border]]&lt;br /&gt;
* 125 by 90&lt;br /&gt;
* The white cross is 20 wide&lt;br /&gt;
* The red cross is 10 wide&lt;br /&gt;
* The cross line intersect at (45, 45)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;blue&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,125,90);&lt;br /&gt;
  ctx.strokeStyle = &#039;white&#039;;&lt;br /&gt;
  ctx.lineWidth = 20;&lt;br /&gt;
  ctx.moveTo(45,0);&lt;br /&gt;
  ctx.lineTo(45,90);&lt;br /&gt;
  ctx.moveTo(0,45);&lt;br /&gt;
  ctx.lineTo(125,45);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
  ctx.strokeStyle = &#039;red&#039;;&lt;br /&gt;
  ctx.lineWidth = 10;&lt;br /&gt;
  ctx.moveTo(45,0);&lt;br /&gt;
  ctx.lineTo(45,90);&lt;br /&gt;
  ctx.moveTo(0,45);&lt;br /&gt;
  ctx.lineTo(125,45);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Trinidad and Tobago==&lt;br /&gt;
&amp;lt;div class=qu height=&amp;quot;100&amp;quot; width=&amp;quot;150&amp;quot;&amp;gt;&lt;br /&gt;
We can start and end lines outside the confines of the surface.&lt;br /&gt;
*The white line has width 35&lt;br /&gt;
*The black line has width 25&lt;br /&gt;
[[Image:flagtrinidad.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=usr lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;red&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,150,100);&lt;br /&gt;
  ctx.lineWidth = 35;&lt;br /&gt;
  ctx.strokeStyle = &#039;white&#039;;&lt;br /&gt;
  ctx.moveTo(0,-25);&lt;br /&gt;
  ctx.lineTo(75,50);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;red&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,150,100);&lt;br /&gt;
  ctx.lineWidth = 35;&lt;br /&gt;
  ctx.strokeStyle = &#039;white&#039;;&lt;br /&gt;
  ctx.moveTo(0,-25);&lt;br /&gt;
  ctx.lineTo(150,125);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
  ctx.lineWidth = 25;&lt;br /&gt;
  ctx.strokeStyle = &#039;black&#039;;&lt;br /&gt;
  ctx.moveTo(0,-25);&lt;br /&gt;
  ctx.lineTo(150,125);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlos</name></author>
	</entry>
	<entry>
		<id>https://progzoo.net/index.php?title=Flags_with_Repeats&amp;diff=719</id>
		<title>Flags with Repeats</title>
		<link rel="alternate" type="text/html" href="https://progzoo.net/index.php?title=Flags_with_Repeats&amp;diff=719"/>
		<updated>2021-09-13T07:22:26Z</updated>

		<summary type="html">&lt;p&gt;Carlos: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;pre id=&#039;shellbody&#039; data-qtp=&#039;canvas&#039;&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can repeat a statement or block of statements with a for loop. The classic &#039;&#039;&#039;for&#039;&#039;&#039; loop takes the following form:&lt;br /&gt;
&lt;br /&gt;
 for(let i = 0; i&amp;lt; 10; i++){&lt;br /&gt;
    console.log(i);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The body of the loop runs 10 times, control variable i takes every value 0,1,2..9 in turn. We can use the value of i inside the loop if required.&lt;br /&gt;
&lt;br /&gt;
You can dive right in or view the instructive example at [[Flag EU]]&lt;br /&gt;
==Bahrain==&lt;br /&gt;
&amp;lt;div class=qu data-width=&amp;quot;250&amp;quot; data-height=&amp;quot;155&amp;quot;&amp;gt;&lt;br /&gt;
The flag of Bahrain has a five irregular pentagons on a red background.&lt;br /&gt;
&lt;br /&gt;
Each pentagon can be represented by five points such as (0,0), (64,0) (100,15) (64,31) and (0,31).&lt;br /&gt;
&lt;br /&gt;
[[Image:flagbahrain.png|left|frame|Flag of Bahrain]]&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;red&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,250,155);&lt;br /&gt;
  for(let i=0;i&amp;lt;3;i++){&lt;br /&gt;
    ctx.fillStyle=&#039;white&#039;;&lt;br /&gt;
    ctx.beginPath();&lt;br /&gt;
    ctx.moveTo(0,0);&lt;br /&gt;
    ctx.lineTo(64,0);&lt;br /&gt;
    ctx.lineTo(100,15);&lt;br /&gt;
    ctx.lineTo(64,31);&lt;br /&gt;
    ctx.lineTo(0,31);&lt;br /&gt;
    ctx.fill();&lt;br /&gt;
    ctx.translate(0,31);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;red&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,250,155);&lt;br /&gt;
  for(let i=0;i&amp;lt;5;i++){&lt;br /&gt;
    ctx.fillStyle=&#039;white&#039;;&lt;br /&gt;
    ctx.beginPath();&lt;br /&gt;
    ctx.moveTo(0,0);&lt;br /&gt;
    ctx.lineTo(64,0);&lt;br /&gt;
    ctx.lineTo(100,15);&lt;br /&gt;
    ctx.lineTo(64,31);&lt;br /&gt;
    ctx.lineTo(0,31);&lt;br /&gt;
    ctx.fill();&lt;br /&gt;
    ctx.translate(0,31);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Qatar==&lt;br /&gt;
&amp;lt;div class=qu data-width=&amp;quot;300&amp;quot; data-height=&amp;quot;153&amp;quot;&amp;gt;&lt;br /&gt;
Consider the neighbouring state Qatar.&lt;br /&gt;
&lt;br /&gt;
* 9 pillars, each pillar is 17 pixels below the previous.&lt;br /&gt;
* The five coordinates of the top pillar are (0,0) (84,0) (125,9) (84,17), (0,17)&lt;br /&gt;
* &#039;&#039;&#039;rgb(128,0,0)&#039;&#039;&#039; is a less jaunty red.&lt;br /&gt;
&lt;br /&gt;
The need for a loop becomes even more obvious for this flag.&lt;br /&gt;
[[Image:flagqatar.png|left|frame|Flag of Qatar]]&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;rgb(128,0,0)&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,250,155);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;rgb(128,0,0)&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,250,155);&lt;br /&gt;
  for(let i=0;i&amp;lt;9;i++){&lt;br /&gt;
    ctx.fillStyle=&#039;white&#039;;&lt;br /&gt;
    ctx.beginPath();&lt;br /&gt;
    ctx.moveTo(0,0);&lt;br /&gt;
    ctx.lineTo(84,0);&lt;br /&gt;
    ctx.lineTo(125,9);&lt;br /&gt;
    ctx.lineTo(84,17);&lt;br /&gt;
    ctx.lineTo(0,17);&lt;br /&gt;
    ctx.fill();&lt;br /&gt;
    ctx.translate(0,17);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==India==&lt;br /&gt;
&amp;lt;div class=qu data-width=&amp;quot;306&amp;quot; data-height=&amp;quot;204&amp;quot;&amp;gt;&lt;br /&gt;
* The flag of India is 306 by 204&lt;br /&gt;
* The orange, white and green stripes are equal sizes.&lt;br /&gt;
* The wheel has radius 30.&lt;br /&gt;
* The wheel has 24 spokes, the spokes are π/12 radians apart.&lt;br /&gt;
&lt;br /&gt;
Whoever wrote the sample code used copy and paste three times, then got bored and gave up. A better programmer would have used a loop.&lt;br /&gt;
This is the phrase that gets repeated:&lt;br /&gt;
  ctx.moveTo(0,0);&lt;br /&gt;
  ctx.lineTo(0,30);&lt;br /&gt;
  ctx.rotate(Math.PI/12);&lt;br /&gt;
&lt;br /&gt;
We have not really done India justice here - the actual flag is much more elegant, the spokes taper and the rim includes decoration. Nevertheless - we apologize to the sub-continent and move on.&lt;br /&gt;
&lt;br /&gt;
[[Image:flagindia.png|left|frame|Flag of India]]&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;orange&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,306,204/3);&lt;br /&gt;
  ctx.fillStyle = &#039;lime&#039;;&lt;br /&gt;
  ctx.fillRect(0,2*204/3,306,204/3);&lt;br /&gt;
  ctx.strokeStyle = &#039;blue&#039;;&lt;br /&gt;
  ctx.lineWidth = 1.5;&lt;br /&gt;
  ctx.translate(153,102);&lt;br /&gt;
  ctx.arc(0,0,30,0,2*Math.PI,true);&lt;br /&gt;
  ctx.moveTo(0,0);&lt;br /&gt;
  ctx.lineTo(0,30);&lt;br /&gt;
  ctx.rotate(Math.PI/12);&lt;br /&gt;
  ctx.moveTo(0,0);&lt;br /&gt;
  ctx.lineTo(0,30);&lt;br /&gt;
  ctx.rotate(Math.PI/12);&lt;br /&gt;
  ctx.moveTo(0,0);&lt;br /&gt;
  ctx.lineTo(0,30);&lt;br /&gt;
  ctx.rotate(Math.PI/12);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;orange&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,306,204/3);&lt;br /&gt;
  ctx.fillStyle = &#039;white&#039;;&lt;br /&gt;
  ctx.fillRect(0,204/3,306,204/3);&lt;br /&gt;
  ctx.fillStyle = &#039;lime&#039;;&lt;br /&gt;
  ctx.fillRect(0,2*204/3,306,204/3);&lt;br /&gt;
  ctx.strokeStyle = &#039;blue&#039;;&lt;br /&gt;
  ctx.lineWidth = 1.5;&lt;br /&gt;
  ctx.translate(153,102);&lt;br /&gt;
  ctx.arc(0,0,30,0,2*Math.PI,true);&lt;br /&gt;
  for(let i=0;i&amp;lt;24;i++){&lt;br /&gt;
    ctx.moveTo(0,0);&lt;br /&gt;
    ctx.lineTo(0,30);&lt;br /&gt;
    ctx.rotate(Math.PI/12);&lt;br /&gt;
  }&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Namibia==&lt;br /&gt;
&amp;lt;div class=qu data-width=&amp;quot;300&amp;quot; data-height=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;
* The joyous flag of Namibia is 300 by 200&lt;br /&gt;
* Each the rightmost triangle has coordinates (19,5) (29,0) (19,-5) relative to the centre of the star burst&lt;br /&gt;
* The star burst is centred at (60,60)&lt;br /&gt;
* The yellow circle has radius 16&lt;br /&gt;
* The small triangles are partially covered by a blue circle of radius 20&lt;br /&gt;
* The right angled triangles are 240 by 160&lt;br /&gt;
* The red stripe is 42 wide&lt;br /&gt;
&lt;br /&gt;
That lazy default programmer has done it again. Copied and pasted the same phrase three times then given up. Thank goodness you are here to fix things up!&lt;br /&gt;
  ctx.beginPath();&lt;br /&gt;
  ctx.moveTo(19,5);&lt;br /&gt;
  ctx.lineTo(29,0);&lt;br /&gt;
  ctx.lineTo(19,-5);&lt;br /&gt;
  ctx.fill();&lt;br /&gt;
  ctx.rotate(Math.PI/6);&lt;br /&gt;
&lt;br /&gt;
[[Image:flagnamibia.png|left|frame|Flag of Namibia]]&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;yellow&#039;;&lt;br /&gt;
  ctx.translate(60,60);&lt;br /&gt;
  &lt;br /&gt;
  ctx.beginPath();&lt;br /&gt;
  ctx.moveTo(19,5);&lt;br /&gt;
  ctx.lineTo(29,0);&lt;br /&gt;
  ctx.lineTo(19,-5);&lt;br /&gt;
  ctx.fill();&lt;br /&gt;
  ctx.rotate(Math.PI/6);&lt;br /&gt;
&lt;br /&gt;
  ctx.beginPath();&lt;br /&gt;
  ctx.moveTo(19,5);&lt;br /&gt;
  ctx.lineTo(29,0);&lt;br /&gt;
  ctx.lineTo(19,-5);&lt;br /&gt;
  ctx.fill();&lt;br /&gt;
  ctx.rotate(Math.PI/6);&lt;br /&gt;
&lt;br /&gt;
  ctx.beginPath();&lt;br /&gt;
  ctx.moveTo(19,5);&lt;br /&gt;
  ctx.lineTo(29,0);&lt;br /&gt;
  ctx.lineTo(19,-5);&lt;br /&gt;
  ctx.fill();&lt;br /&gt;
  ctx.rotate(Math.PI/6);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;white&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,300,200);&lt;br /&gt;
  ctx.strokeStyle = &#039;red&#039;;&lt;br /&gt;
  ctx.lineWidth = 42;&lt;br /&gt;
  ctx.moveTo(0,200);&lt;br /&gt;
  ctx.lineTo(300,0);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
  ctx.fillStyle = &#039;blue&#039;;&lt;br /&gt;
  ctx.moveTo(0,0);&lt;br /&gt;
  ctx.lineTo(240,0);&lt;br /&gt;
  ctx.lineTo(0,160);&lt;br /&gt;
  ctx.fill();&lt;br /&gt;
  ctx.beginPath();&lt;br /&gt;
  ctx.fillStyle = &#039;lime&#039;;&lt;br /&gt;
  ctx.moveTo(300,200);&lt;br /&gt;
  ctx.lineTo(60,200);&lt;br /&gt;
  ctx.lineTo(300,40);&lt;br /&gt;
  ctx.fill();&lt;br /&gt;
  ctx.beginPath();&lt;br /&gt;
  ctx.fillStyle = &#039;yellow&#039;;&lt;br /&gt;
  ctx.translate(60,60);&lt;br /&gt;
  ctx.arc(0,0,16,0,2*Math.PI);&lt;br /&gt;
  for(let i=0;i&amp;lt;12;i++){&lt;br /&gt;
    ctx.fill();&lt;br /&gt;
    ctx.beginPath();&lt;br /&gt;
    ctx.moveTo(19,5);&lt;br /&gt;
    ctx.lineTo(29,0);&lt;br /&gt;
    ctx.lineTo(19,-5);&lt;br /&gt;
    ctx.fill();&lt;br /&gt;
    ctx.rotate(Math.PI/6);&lt;br /&gt;
  }&lt;br /&gt;
  ctx.fillStyle = &#039;blue&#039;;&lt;br /&gt;
  ctx.arc(0,0,20,0,2*Math.PI);&lt;br /&gt;
  ctx.fillStyle = &#039;yellow&#039;;&lt;br /&gt;
  ctx.arc(0,0,16,0,2*Math.PI);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Venezuela==&lt;br /&gt;
&amp;lt;div class=qu data-width=&amp;quot;180&amp;quot; data-height=&amp;quot;120&amp;quot;&amp;gt;&lt;br /&gt;
* There are eight stars arranged around circle centre (90,86) radius 36&lt;br /&gt;
* The angle between stars is 20&amp;amp;deg;&lt;br /&gt;
* Each star has radius 5&lt;br /&gt;
[http://www.vexilla-mundi.com/venezuela_flag.html construction sheet for Venezuela]&lt;br /&gt;
[[Image:flagvenezuala.png|left|frame|Flag of Venezuela]]&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;yellow&#039;;&lt;br /&gt;
  ctx.translate(60,60);&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;yellow&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,180,40);&lt;br /&gt;
  ctx.fillStyle = &#039;blue&#039;;&lt;br /&gt;
  ctx.fillRect(0,40,180,40);&lt;br /&gt;
  ctx.fillStyle = &#039;red&#039;;&lt;br /&gt;
  ctx.fillRect(0,80,180,40);&lt;br /&gt;
  ctx.translate(90,84);&lt;br /&gt;
  ctx.fillStyle = &#039;white&#039;;&lt;br /&gt;
  let n = 8;&lt;br /&gt;
  ctx.rotate(-20*(n-1)/2*Math.PI/180);&lt;br /&gt;
  for(let i = 0;i&amp;lt;n;i++){&lt;br /&gt;
    ctx.translate(0,-36);&lt;br /&gt;
    star(ctx);&lt;br /&gt;
    ctx.translate(0,36);&lt;br /&gt;
    ctx.rotate(20*Math.PI/180);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function star(ctx){&lt;br /&gt;
  ctx.beginPath();&lt;br /&gt;
  ctx.scale(5.0/100,5.0/100);&lt;br /&gt;
  [[0,-100],[22,-31],[95,-31],[36,12],[59,81],&lt;br /&gt;
   [0,38],[-59,81],[-36,12],[-95,-31],[-22,-31]]&lt;br /&gt;
  .forEach(xy=&amp;gt;ctx.lineTo(xy[0],xy[1]));&lt;br /&gt;
  ctx.fill();&lt;br /&gt;
  ctx.scale(100/5,100/5);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlos</name></author>
	</entry>
	<entry>
		<id>https://progzoo.net/index.php?title=Flags_with_Repeats&amp;diff=718</id>
		<title>Flags with Repeats</title>
		<link rel="alternate" type="text/html" href="https://progzoo.net/index.php?title=Flags_with_Repeats&amp;diff=718"/>
		<updated>2021-09-13T06:49:50Z</updated>

		<summary type="html">&lt;p&gt;Carlos: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;pre id=&#039;shellbody&#039; data-qtp=&#039;canvas&#039;&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can repeat a statement or block of statements with a for loop. The classic &#039;&#039;&#039;for&#039;&#039;&#039; loop takes the following form:&lt;br /&gt;
&lt;br /&gt;
 for(let i = 0; i&amp;lt; 10; i++){&lt;br /&gt;
    console.log(i);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The body of the loop runs 10 times, control variable i takes every value 0,1,2..9 in turn. We can use the value of i inside the loop if required.&lt;br /&gt;
&lt;br /&gt;
You can dive right in or view the instructive example at [[Flag EU]]&lt;br /&gt;
==Bahrain==&lt;br /&gt;
&amp;lt;div class=qu data-width=&amp;quot;250&amp;quot; data-height=&amp;quot;155&amp;quot;&amp;gt;&lt;br /&gt;
The flag of Bahrain has a five irregular pentagons on a red background.&lt;br /&gt;
&lt;br /&gt;
Each pentagon can be represented by five points such as (0,0), (64,0) (100,15) (64,31) and (0,31).&lt;br /&gt;
&lt;br /&gt;
[[Image:flagbahrain.png|left|frame|Flag of Bahrain]]&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;red&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,250,155);&lt;br /&gt;
  for(let i=0;i&amp;lt;3;i++){&lt;br /&gt;
    ctx.fillStyle=&#039;white&#039;;&lt;br /&gt;
    ctx.beginPath();&lt;br /&gt;
    ctx.moveTo(0,0);&lt;br /&gt;
    ctx.lineTo(64,0);&lt;br /&gt;
    ctx.lineTo(100,15);&lt;br /&gt;
    ctx.lineTo(64,31);&lt;br /&gt;
    ctx.lineTo(0,31);&lt;br /&gt;
    ctx.fill();&lt;br /&gt;
    ctx.translate(0,31);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;red&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,250,155);&lt;br /&gt;
  for(let i=0;i&amp;lt;5;i++){&lt;br /&gt;
    ctx.fillStyle=&#039;white&#039;;&lt;br /&gt;
    ctx.beginPath();&lt;br /&gt;
    ctx.moveTo(0,0);&lt;br /&gt;
    ctx.lineTo(64,0);&lt;br /&gt;
    ctx.lineTo(100,15);&lt;br /&gt;
    ctx.lineTo(64,31);&lt;br /&gt;
    ctx.lineTo(0,31);&lt;br /&gt;
    ctx.fill();&lt;br /&gt;
    ctx.translate(0,31);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Qatar==&lt;br /&gt;
&amp;lt;div class=qu data-width=&amp;quot;300&amp;quot; data-height=&amp;quot;153&amp;quot;&amp;gt;&lt;br /&gt;
Consider the neighbouring state Qatar.&lt;br /&gt;
&lt;br /&gt;
* 9 pillars, each pillar is 17 pixels below the previous.&lt;br /&gt;
* The five coordinates of the top pillar are (0,0) (84,0) (125,9) (84,17), (0,17)&lt;br /&gt;
* &#039;&#039;&#039;rgb(128,0,0)&#039;&#039;&#039; is a less jaunty red.&lt;br /&gt;
&lt;br /&gt;
The need for a loop becomes even more obvious for this flag.&lt;br /&gt;
[[Image:flagqatar.png|left|frame|Flag of Qatar]]&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;rgb(128,0,0)&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,250,155);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;rgb(128,0,0)&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,250,155);&lt;br /&gt;
  for(let i=0;i&amp;lt;9;i++){&lt;br /&gt;
    ctx.fillStyle=&#039;white&#039;;&lt;br /&gt;
    ctx.beginPath();&lt;br /&gt;
    ctx.moveTo(0,0);&lt;br /&gt;
    ctx.lineTo(84,0);&lt;br /&gt;
    ctx.lineTo(125,9);&lt;br /&gt;
    ctx.lineTo(84,17);&lt;br /&gt;
    ctx.lineTo(0,17);&lt;br /&gt;
    ctx.fill();&lt;br /&gt;
    ctx.translate(0,17);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==India==&lt;br /&gt;
&amp;lt;div class=qu data-width=&amp;quot;306&amp;quot; data-height=&amp;quot;204&amp;quot;&amp;gt;&lt;br /&gt;
* The flag of India is 306 by 204&lt;br /&gt;
* The orange, white and green stripes are equal sizes.&lt;br /&gt;
* The wheel has radius 30.&lt;br /&gt;
* The wheel has 24 spokes, the spokes are π/12 radians apart.&lt;br /&gt;
&lt;br /&gt;
Whoever wrote the sample code used copy and paste three times, then got bored and gave up. A better programmer would have used a loop.&lt;br /&gt;
This is the phrase that gets repeated:&lt;br /&gt;
  ctx.moveTo(0,0);&lt;br /&gt;
  ctx.lineTo(0,30);&lt;br /&gt;
  ctx.rotate(Math.PI/12);&lt;br /&gt;
&lt;br /&gt;
We have not really done India justice here - the actual flag is much more elegant, the spokes taper and the rim includes decoration. Nevertheless - we apologize to the sub-continent and move on.&lt;br /&gt;
&lt;br /&gt;
[[Image:flagindia.png|left|frame|Flag of India]]&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;orange&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,306,204/3);&lt;br /&gt;
  ctx.fillStyle = &#039;lime&#039;;&lt;br /&gt;
  ctx.fillRect(0,2*204/3,306,204/3);&lt;br /&gt;
  ctx.strokeStyle = &#039;blue&#039;;&lt;br /&gt;
  ctx.lineWidth = 1.5;&lt;br /&gt;
  ctx.translate(153,102);&lt;br /&gt;
  ctx.arc(0,0,30,0,2*Math.PI,true);&lt;br /&gt;
  ctx.moveTo(0,0);&lt;br /&gt;
  ctx.lineTo(0,30);&lt;br /&gt;
  ctx.rotate(Math.PI/12);&lt;br /&gt;
  ctx.moveTo(0,0);&lt;br /&gt;
  ctx.lineTo(0,30);&lt;br /&gt;
  ctx.rotate(Math.PI/12);&lt;br /&gt;
  ctx.moveTo(0,0);&lt;br /&gt;
  ctx.lineTo(0,30);&lt;br /&gt;
  ctx.rotate(Math.PI/12);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;orange&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,306,204/3);&lt;br /&gt;
  ctx.fillStyle = &#039;white&#039;;&lt;br /&gt;
  ctx.fillRect(0,204/3,306,204/3);&lt;br /&gt;
  ctx.fillStyle = &#039;lime&#039;;&lt;br /&gt;
  ctx.fillRect(0,2*204/3,306,204/3);&lt;br /&gt;
  ctx.strokeStyle = &#039;blue&#039;;&lt;br /&gt;
  ctx.lineWidth = 1.5;&lt;br /&gt;
  ctx.translate(153,102);&lt;br /&gt;
  ctx.arc(0,0,30,0,2*Math.PI,true);&lt;br /&gt;
  for(let i=0;i&amp;lt;24;i++){&lt;br /&gt;
    ctx.moveTo(0,0);&lt;br /&gt;
    ctx.lineTo(0,30);&lt;br /&gt;
    ctx.rotate(Math.PI/12);&lt;br /&gt;
  }&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Namibia==&lt;br /&gt;
&amp;lt;div class=qu data-width=&amp;quot;300&amp;quot; data-height=&amp;quot;200&amp;quot;&amp;gt;&lt;br /&gt;
* The joyous flag of Namibia is 300 by 200&lt;br /&gt;
* Each the rightmost triangle has coordinates (19,5) (29,0) (19,-5) relative to the centre of the star burst&lt;br /&gt;
* The star burst is centred at (60,60)&lt;br /&gt;
* The yellow circle has radius 16&lt;br /&gt;
* The small triangles are partially covered by a blue circle of radius 20&lt;br /&gt;
* The right angled triangles are 240 by 160&lt;br /&gt;
* The red stripe is 42 wide&lt;br /&gt;
&lt;br /&gt;
That lazy default programmer has done it again. Copied and pasted the same phrase three times then given up. Thank goodness you are here to fix things up!&lt;br /&gt;
  ctx.beginPath();&lt;br /&gt;
  ctx.moveTo(19,5);&lt;br /&gt;
  ctx.lineTo(29,0);&lt;br /&gt;
  ctx.lineTo(19,-5);&lt;br /&gt;
  ctx.fill();&lt;br /&gt;
  ctx.rotate(Math.PI/6);&lt;br /&gt;
&lt;br /&gt;
[[Image:flagnamibia.png|left|frame|Flag of Namibia]]&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;yellow&#039;;&lt;br /&gt;
  ctx.translate(60,60);&lt;br /&gt;
  &lt;br /&gt;
  ctx.beginPath();&lt;br /&gt;
  ctx.moveTo(19,5);&lt;br /&gt;
  ctx.lineTo(29,0);&lt;br /&gt;
  ctx.lineTo(19,-5);&lt;br /&gt;
  ctx.fill();&lt;br /&gt;
  ctx.rotate(Math.PI/6);&lt;br /&gt;
&lt;br /&gt;
  ctx.beginPath();&lt;br /&gt;
  ctx.moveTo(19,5);&lt;br /&gt;
  ctx.lineTo(29,0);&lt;br /&gt;
  ctx.lineTo(19,-5);&lt;br /&gt;
  ctx.fill();&lt;br /&gt;
  ctx.rotate(Math.PI/6);&lt;br /&gt;
&lt;br /&gt;
  ctx.beginPath();&lt;br /&gt;
  ctx.moveTo(19,5);&lt;br /&gt;
  ctx.lineTo(29,0);&lt;br /&gt;
  ctx.lineTo(19,-5);&lt;br /&gt;
  ctx.fill();&lt;br /&gt;
  ctx.rotate(Math.PI/6);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;white&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,300,200);&lt;br /&gt;
  ctx.strokeStyle = &#039;red&#039;;&lt;br /&gt;
  ctx.lineWidth = 42;&lt;br /&gt;
  ctx.moveTo(0,200);&lt;br /&gt;
  ctx.lineTo(300,0);&lt;br /&gt;
  ctx.stroke();&lt;br /&gt;
  ctx.fillStyle = &#039;blue&#039;;&lt;br /&gt;
  ctx.moveTo(0,0);&lt;br /&gt;
  ctx.lineTo(240,0);&lt;br /&gt;
  ctx.lineTo(0,160);&lt;br /&gt;
  ctx.fill();&lt;br /&gt;
  ctx.beginPath();&lt;br /&gt;
  ctx.fillStyle = &#039;lime&#039;;&lt;br /&gt;
  ctx.moveTo(300,200);&lt;br /&gt;
  ctx.lineTo(60,200);&lt;br /&gt;
  ctx.lineTo(300,40);&lt;br /&gt;
  ctx.fill();&lt;br /&gt;
  ctx.beginPath();&lt;br /&gt;
  ctx.fillStyle = &#039;yellow&#039;;&lt;br /&gt;
  ctx.translate(60,60);&lt;br /&gt;
  ctx.arc(0,0,16,0,2*Math.PI);&lt;br /&gt;
  for(let i=0;i&amp;lt;12;i++){&lt;br /&gt;
    ctx.fill();&lt;br /&gt;
    ctx.beginPath();&lt;br /&gt;
    ctx.moveTo(19,5);&lt;br /&gt;
    ctx.lineTo(29,0);&lt;br /&gt;
    ctx.lineTo(19,-5);&lt;br /&gt;
    ctx.fill();&lt;br /&gt;
    ctx.rotate(Math.PI/6);&lt;br /&gt;
  }&lt;br /&gt;
  ctx.fillStyle = &#039;blue&#039;;&lt;br /&gt;
  ctx.arc(0,0,20,0,2*Math.PI);&lt;br /&gt;
  ctx.fillStyle = &#039;yellow&#039;;&lt;br /&gt;
  ctx.arc(0,0,16,0,2*Math.PI);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Venezuela==&lt;br /&gt;
&amp;lt;div class=qu data-width=&amp;quot;180&amp;quot; data-height=&amp;quot;120&amp;quot;&amp;gt;&lt;br /&gt;
* There are eight stars arranged around circle centre (90,86) radius 36&lt;br /&gt;
* The angle between stars is 20&amp;amp;deg;&lt;br /&gt;
* Each star has radius 5&lt;br /&gt;
[http://www.vexilla-mundi.com/venezuela_flag.html construction sheet for Venezuela]&lt;br /&gt;
[[Image:flagvenezuela.png|left|frame|Flag of Venezuela]]&lt;br /&gt;
&amp;lt;pre class=usr&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;yellow&#039;;&lt;br /&gt;
  ctx.translate(60,60);&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre class=ans&amp;gt;&lt;br /&gt;
function drawFlag(ctx)&lt;br /&gt;
{&lt;br /&gt;
  ctx.fillStyle = &#039;yellow&#039;;&lt;br /&gt;
  ctx.fillRect(0,0,180,40);&lt;br /&gt;
  ctx.fillStyle = &#039;blue&#039;;&lt;br /&gt;
  ctx.fillRect(0,40,180,40);&lt;br /&gt;
  ctx.fillStyle = &#039;red&#039;;&lt;br /&gt;
  ctx.fillRect(0,80,180,40);&lt;br /&gt;
  ctx.translate(90,84);&lt;br /&gt;
  ctx.fillStyle = &#039;white&#039;;&lt;br /&gt;
  let n = 8;&lt;br /&gt;
  ctx.rotate(-20*(n-1)/2*Math.PI/180);&lt;br /&gt;
  for(let i = 0;i&amp;lt;n;i++){&lt;br /&gt;
    ctx.translate(0,-36);&lt;br /&gt;
    star(ctx);&lt;br /&gt;
    ctx.translate(0,36);&lt;br /&gt;
    ctx.rotate(20*Math.PI/180);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
function star(ctx){&lt;br /&gt;
  ctx.beginPath();&lt;br /&gt;
  ctx.scale(5.0/100,5.0/100);&lt;br /&gt;
  [[0,-100],[22,-31],[95,-31],[36,12],[59,81],&lt;br /&gt;
   [0,38],[-59,81],[-36,12],[-95,-31],[-22,-31]]&lt;br /&gt;
  .forEach(xy=&amp;gt;ctx.lineTo(xy[0],xy[1]));&lt;br /&gt;
  ctx.fill();&lt;br /&gt;
  ctx.scale(100/5,100/5);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Carlos</name></author>
	</entry>
</feed>