Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <script src=""></script>
<div id="wrapper">
  <div id="mysamplingtask"></div>
  <div id="user-ratings"></div>


                #mysamplingtask {
  width: 30%;
  font-size: 1.2em;

#user-ratings {
  width: 30%;
  height: 499px;
  padding-left: 10px;

#wrapper {
  display: flex;



                function displayRatings() {
  const ratings = this.getRatingsAsJSON();
  const ratingsDiv = document.getElementById("user-ratings");
  ratingsDiv.innerHTML = "";
  const ratingsKeys = Object.keys(ratings);
  const firstDisplayed = Math.max(0, ratingsKeys.length - 15);
  var i = 0;
  for (k in Object.keys(ratings)) {
    if (i >= firstDisplayed) {
      let span = document.createElement("span");
      span.textContent = "Rating at " + k + " seconds: " + ratings[k];

const aff_sampler = new AffectiveSampler({
  parentId: "mysamplingtask",
    "", // The media to show.
  mediaType: "video", // The type of the media, can be "video" or "audio"
  showMediaControls: false, // Whether the show the media controls. If false, only a play/pause button will be displayed.
  canPauseMedia: true,
  sliderMin: -50, // The minimum value of the affective slider
  sliderMax: 50, // The maximum value of the affective slider
  timeResolution: 1, // The time resolution (in seconds) at which to sample. Should not be lower than 1.
  textLabel: "Your current happiness rating is: ", // The label to display next to the current affective rating.
  minLabel: "Sad", // The left anchor of the affective scale.
  maxLabel: "Happy", // The right anchor of the affective scale.
  onInterval: displayRatings, // A function to call when recording a value.
  onMediaEnd: function() {
    console.log("The media has ended");
  } // A function to call when the media ends.