title: Promises, I have some trouble getting the return of another function
body: <p>I have a canvas that I want to download as PNG as an image, I got that to work but I want to have my user to choose the name of the file.</p>
  
  <p>I tried to get him to write name of the file with a promise. But my question is, can't I create a function where he asks the name of the file to the user and when it return the name the download begins?
  Here is my code:</p>
  
  <pre><code>function downloadAsPNG() {
    //Download the image
    let image = new Image();
    image.src = document.getElementById("defaultCanvas0").toDataURL("image/png");
    new Promise(function(nameOfFile) {
      nameOfFile(askNameOfFile());
    }).then(function(result) {
      let nameFile = result + ".png";
      document.getElementById("downloadPNG").download = nameFile;
      return document.getElementById("downloadPNG").href = image['attributes']['src']['nodeValue'];
    });
  }
  </code></pre>
  
  <p>Here is the function that I want to call to know the name of the file:</p>
  
  <pre><code>function askNameOfFile() {
    let nameOfFile = '';
    let inputNameHTML = "&lt;form id='FormFileName'&gt;&lt;input type='text' id='nameOfFile'&gt;&lt;input type='submit' id='sendNameOfFile'&gt;&lt;/form&gt;";
    document.getElementById('NameOfFileContainer').innerHTML = inputNameHTML;
    document.getElementById('FormFileName').addEventListener('submit', function(event) {
      event.preventDefault();
      nameOfFile = event.target.childNodes[0].value;
      return nameOfFile;
    });
  }
  </code></pre>
  
  <p>I know that instead of using a second function I could simply write what I have in the promise but I want to use that function I other function for example upload the file to the server or download as JPEG.</p>