World Factbook: Difference between revisions
		
		
		
		Jump to navigation
		Jump to search
		
| Line 21: | Line 21: | ||
   .then((r)=>{  |    .then((r)=>{  | ||
      let letters = new Set(r.map(c=>c.name[0]));  |       let letters = new Set(r.map(c=>c.name[0]));  | ||
     for(let a of letters){  | |||
       let b = document.createElement('button');  | |||
       b.innerText = a;  | |||
       document.body.append(b);  | |||
     }  | |||
  });  | |||
</pre>  | |||
</div>  | |||
==Get a button for each continent==  | |||
* Show a button for each continent  | |||
<div class=qu>  | |||
<pre class=usr>  | |||
</pre>  | |||
<pre class=ans>  | |||
fetch('/worldl.json')  | |||
  .then((r)=>r.json())  | |||
  .then((r)=>{  | |||
     let letters = new Set(r.map(c=>c.continent));  | |||
      for(let a of letters){  |       for(let a of letters){  | ||
        let b = document.createElement('button');  |         let b = document.createElement('button');  | ||
Revision as of 09:33, 22 January 2022
Get a button for each letter
- Show a button for each letter that a country can begin with
 - You can use a Set to remove duplicates from a list.
 
fetch('/worldl.json')
  .then((r)=>r.json())
  .then((r)=>{
     let letters = r.map(c=>c.name[0]);
     for(let a of letters){
       let b = document.createElement('button');
       b.innerText = a;
       document.body.append(b);
     }
  });
fetch('/worldl.json')
  .then((r)=>r.json())
  .then((r)=>{
     let letters = new Set(r.map(c=>c.name[0]));
     for(let a of letters){
       let b = document.createElement('button');
       b.innerText = a;
       document.body.append(b);
     }
  });
Get a button for each continent
- Show a button for each continent
 
fetch('/worldl.json')
  .then((r)=>r.json())
  .then((r)=>{
     let letters = new Set(r.map(c=>c.continent));
     for(let a of letters){
       let b = document.createElement('button');
       b.innerText = a;
       document.body.append(b);
     }
  });