Home > Net >  GETFOOTNOTES() and ALERT: How can I verify i f students append a footnote?
GETFOOTNOTES() and ALERT: How can I verify i f students append a footnote?

Time:05-06

I want to verify on google docs if students added a footnote. My scripts doesn't run.

script:

  function addNote () {
  const menuMessage = DocumentApp.getUi();
  const doc = DocumentApp.getActiveDocument();
  const notePiedPage = doc.getFootnotes();

  if(notePiedPage == DocumentApp.ElementType.FOOTNOTE){
    menuMessage.alert('Génial, le 3e mot de passe est BISCOTO');
  } 
  else {
    menuMessage.alert('Erreur...');
  }
}

CodePudding user response:

This looks incorrect:

const notePiedPage = doc.getFootnotes();
if(notePiedPage == DocumentApp.ElementType.FOOTNOTE){
  menuMessage.alert('Génial, le 3e mot de passe est BISCOTO');
} 

because getFootnotes() returns an array

Try something like this:

function HowManyFootNotes() {
  const ui = DocumentApp.getUi();
  const doc = DocumentApp.getActiveDocument();
  const fA = doc.getFootnotes();
  if (fA.length > 0) {
    ui.alert(`This document has ${fA.length} footnotes`)
  }
}

Class Footnote

  • Related