<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Facilo-dev</title>
    <description>The latest articles on DEV Community by Facilo-dev (@facilodev).</description>
    <link>https://dev.to/facilodev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4252634%2Fdfd5467b-6f8d-48aa-ac80-7f12e84c8d35.png</url>
      <title>DEV Community: Facilo-dev</title>
      <link>https://dev.to/facilodev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/facilodev"/>
    <language>en</language>
    <item>
      <title>Negative marking in Google Forms with Apps Script</title>
      <dc:creator>Facilo-dev</dc:creator>
      <pubDate>Thu, 19 Nov 2026 02:19:42 +0000</pubDate>
      <link>https://dev.to/facilodev/negative-marking-in-google-forms-with-apps-script-2035</link>
      <guid>https://dev.to/facilodev/negative-marking-in-google-forms-with-apps-script-2035</guid>
      <description>&lt;p&gt;Google Forms quizzes have one scoring rule: a right answer gets its points, everything else gets 0. A wrong answer and a blank answer score the same. That's fine for a pop quiz, but many real exams (Spanish civil-service exams and many entrance tests) take marks off for wrong answers: −1/3, −1/4, +4/−1 and so on. Run a mock exam in Forms and every student's mark comes out too high.&lt;/p&gt;

&lt;p&gt;We built a small add-on, &lt;a href="https://notajusta.facilo.es/en/" rel="noopener noreferrer"&gt;Nota Justa&lt;/a&gt;, that fixes this inside Forms itself. This post shows the approach, since most of it is plain Apps Script you can reuse.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea: write a negative score per question
&lt;/h2&gt;

&lt;p&gt;Forms won't let you set "wrong = −1/3" in the editor, but the Apps Script &lt;code&gt;FormApp&lt;/code&gt; API lets you set any score on a response item, negative included. So:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Read the answer key from the form.&lt;/li&gt;
&lt;li&gt;For each response, decide right / wrong / blank from the key.&lt;/li&gt;
&lt;li&gt;Give each wrong answer a negative score, and give right and blank answers their usual points and 0.&lt;/li&gt;
&lt;li&gt;Save the grades back to the response.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The total Forms shows (and the score students see when you release grades) is now the penalised mark.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading the key
&lt;/h2&gt;

&lt;p&gt;Multiple-choice and checkbox items expose their points and which choices are correct:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;asMultipleChoiceItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;points&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getPoints&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;correct&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getChoices&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isCorrectAnswer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Writing the score back
&lt;/h2&gt;

&lt;p&gt;This is the core of it. For each question you want to change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;grade&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;itemsById&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ir&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getGradableResponseForItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;itemsById&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;ir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setScore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;        &lt;span class="c1"&gt;// e.g. -0.33 for a wrong answer worth 1 point&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;withItemGrade&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ir&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// then, once per batch of responses:&lt;/span&gt;
&lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;submitGrades&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;responses&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details took a while to get right:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Judge from the key, never from the current score.&lt;/strong&gt; After the first pass, the score Forms holds is already your penalised one. If you infer "wrong" from "score is 0", a second run goes wrong. Re-deriving right/wrong/blank from the answer key every time makes rescoring safe to repeat.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rounding.&lt;/strong&gt; A −1/3 penalty can't be stored exactly. We round each penalty to 2 decimals and put the leftover on the last penalised question, so the total equals the exact mark rounded once.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Existing responses: work in chunks
&lt;/h2&gt;

&lt;p&gt;Apps Script stops a run at 6 minutes. A form with a few thousand responses can hit that, so the rescore works in chunks: it processes responses for a fixed time, calls &lt;code&gt;form.submitGrades()&lt;/code&gt; every 50, saves its position in &lt;code&gt;PropertiesService.getDocumentProperties()&lt;/code&gt;, and the sidebar calls it again until it's done. If the sidebar closes halfway, nothing is lost: the next open carries on from the saved position.&lt;/p&gt;

&lt;h2&gt;
  
  
  New responses: an installable trigger
&lt;/h2&gt;

&lt;p&gt;For new responses, the add-on installs an &lt;code&gt;onFormSubmit&lt;/code&gt; trigger once:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nc"&gt;ScriptApp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newTrigger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'onSubmit_'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forForm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onFormSubmit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the handler, take a document lock (two students can submit at the same moment), rescore only &lt;code&gt;e.response&lt;/code&gt;, and call &lt;code&gt;form.submitGrades([response])&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scopes
&lt;/h2&gt;

&lt;p&gt;It runs with &lt;code&gt;forms.currentonly&lt;/code&gt; (only the form it's installed in), &lt;code&gt;script.container.ui&lt;/code&gt; for the sidebar, &lt;code&gt;script.scriptapp&lt;/code&gt; for the trigger, &lt;code&gt;drive.file&lt;/code&gt; for the optional results sheet, and &lt;code&gt;userinfo.email&lt;/code&gt;, used only to make a hashed ID for the Pro licence check. Responses never leave Google.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it doesn't do
&lt;/h2&gt;

&lt;p&gt;It doesn't build the quiz. It isn't on the Workspace Marketplace yet: you paste two files into Extensions → Apps Script, one form at a time. Grid questions can't be rescored through this API, so they're only counted in the results sheet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it or read the code
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Step-by-step guide: &lt;a href="https://notajusta.facilo.es/en/negative-marking-google-forms/" rel="noopener noreferrer"&gt;Negative marking in Google Forms&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Source: &lt;a href="https://github.com/Facilo-es/nota-justa" rel="noopener noreferrer"&gt;github.com/Facilo-es/nota-justa&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The free version has −1/3, −1/4 or your own rule and the class average out of 10 in the sidebar, with no response limit. Pro adds more rules (−1/2, by number of options, groups of wrong answers, +4/−1), any scale, your own pass mark and a results sheet with ranking and the most-missed questions.&lt;/p&gt;

</description>
      <category>googleappsscript</category>
      <category>javascript</category>
      <category>education</category>
      <category>googleforms</category>
    </item>
  </channel>
</rss>
