Certificate of Completion with DateStamp

Jan 02, 2021

Hello Anyone,

 

I'm new to Javascript and have been studying on how to have the numerical date part automatically stamped on my Certificate of Completion using a code. Currently I have my Certificate formatted like this:

                                       "On this 4th day of December, 2020..."

The code I have below works however every numerical date ends with "th" (Ex. 1th, 2th, 3th instead of 1st, 2nd, 3rd...etc) Can someone give me the code so the ending will match with the numerical date? Any help will be greatly appreciated!

var player = GetPlayer();

var currentDate = new Date();

var day = currentDate.getDate();

if(day<10) {

day=''+day;

}

player.SetVar("Day", day + "th");

19 Replies
Dave Cox

Hi Mario,

Your statement in the if section is broken as it only has a single quote. I'm not sure what you wanted to do in that statement. Maybe add the leading 0?

Anyway, your setting the "th" to the end of the string when you return the value to Storyline with the player.SetVar statement. What you need to do is set the string up as needed, and then just return the prepared string. Perhaps the easiest way to do this is with a switch statement.

Try this:

var player = GetPlayer();
var currentDate = new Date();
var day = currentDate.getDate();
var txtDay = "";

switch (day) {
 case 1:
  txtDay = "1st";
  break;
 case 2:
  txtDay = "2nd";
  break;
 default:
  txtDay = day + "th";
}
player.SetVar("Day",txtDay);

If you are interested in improving your JavaScript, w3schools.com is a really great free resource that does a really great job of explaining all about JavaScript.

Best Regards,

Dave

Dave Cox

Hi Mario,

I'm pretty sure that there isn't anything in that code that would affect the placement of your text box, as we are only setting the value of the text variable.

I'm not sure how you are doing your certificate, but I've done this several times. The way that I create the certificate is to create an HTML/CSS page that I include in the project. In the web page, I create HTML/CSS statements for how the certificate will look on screen, and populate fields for certificate name, user name, and date with my design for how it will look when printed. This way, I can make sure that the printed certificate will fit on the page, and look the way it was designed both when displayed and when printed. This also allows me to put graphics on the certificate that make it look official, and make it hard to forge.

Mario Taplin

I've been practicing this and I'm not sure what I'm doing wrong. It looks like I want it before I publish it but when I print, some of my text (On this...) disappears. If you have a minutes I've attached my certificate. PLEASE tell me what I'm doing wrong. This is driving me crazy

Dave Cox

Hi Mario, 

I don't see the Certificate.html file that your print script references.

It looks like you are attempting to print the slide, so here is another way of printing that I came up with for another user. This script allows you to print the slide on paper as it is displayed on the slide.

It's a very long script, so I've just added it into the script for the slide. See if this will work for you.

Dave

Mario Taplin

You’ve been such a great help so I’m hoping you can answer this for me: (last time and I won’t both you 😊)

 

How do I get rid of or make invisible the print button and the edges (highlighted in green) so when my students print the certificate, it won’t show up? (see attached)

And lastly, the code you gave me works. So I added case 3-7 to add the format to the 3rd, 21st, 22nd, 23rd, and 31st. All others are defaulted to “th”. Do you think the code below will work to take care of the remaining dates?

 

var player = GetPlayer();

var currentDate = new Date();

var day = currentDate.getDate();

var txtDay = "";

 

switch (day) {

 case 1:

  txtDay = "1st";

  break;

 case 2:

  txtDay = "2nd";

  break;

 case 3:

  txtDay = "3rd";

  break;

 case 4:

  txtDay = "21st";

  break;

 case 5:

  txtDay = "22nd";

  break;

 case 6:

  txtDay = "23rd";

  break;

 case 7:

  txtDay = "31st";

  break;

 default:

  txtDay = day + "th";

}

player.SetVar("Day",txtDay);

Mario Taplin

Hi Dave.

I just happen to be searching for answers to another question I have and came across this post. I'm sorry I'm just seeing this, as I don't receive notifications through my email when someone has replied.

Thank you for the update on this. I was just having my students print it with the header and footer, so this is fantastic. I do have another question. When I print it, the certificate doesn't scale to fit the entire page. I've tried changing the scale settings but none seem to work. Is there a way so the certificate will take up the entire print page? Or does this have nothing to do with JS?

Mario Taplin

As I'm studying the code, I came upon this:

 

@page {size: auto A4 landscape; margin: 3mm; }
.slide-container, .slide-container * {
visibility: visible !important;
margin-top: 0px !important;
margin-left: 0px !important;

I would think it would make the margins from top to bottom at 0. I'm not sure why it prints as a mini certificate