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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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.


                <!-- Challenge
1. Create a page with (i). An element for number, (ii). An image (iii). An ul tag for list of images (iv)A 'Check result' button (v). A text to show result
2. Generate random number and put it in (i)
3. On clicking the image it add an li with the image inside UL tag
4. Onlciking check result button, compare random with number of images inside UL, if both are same show Correct answer else worng answer in result box.
<div class="container">
  <div class="row">
    <div class="col-md-12">
      <h4>Select <span id="randomNumber"></span> <span id="item"></span>s</h4>
  <div class="row mb-10">
    <div class="col-md-12">
      <img id="actionImage" src="" alt="Tiger" />
  <div class="row">
    <div class="col-md-12">
      <ul id="imgList"></ul>

  <div class="row">
    <div class="col-md-12">
      <button id="btnResult" class="btn btn-primary">Check Result</button>
      <b id="output"></b>


                #imgList {
  margin: 0;
  padding: 0;
  li, img {
    border-radius: 10px;
    width: 100px;
  li {
    display: inline-block;
    list-style: none;
    margin: 10px 5px;

.mb-10 {
  margin-bottom: 10px;


                $(function() { //iife
  var elements = {
    random: $("#randomNumber"),
    item: $("#item"),
    sourceImage: $("#actionImage"),
    targetImage: $("<img>"),
    imageList: $("#imgList"),
    list: $("<li>"),
    btnResult: $("#btnResult"),
    output: $("#output")
    data = {
      random: Math.floor(9 * Math.random() + 2),
      image: elements.sourceImage.attr("src"),
      item: elements.sourceImage.attr("alt")
    events = {
      init: function() {
        elements.random.text(data.random), elements.item.text(data.item), elements.targetImage.attr({
          alt: "list image",
          src: data.image
        }), elements.list.append(elements.targetImage),
      addImage: function() {
      showResult: function() { 
        var result = "Correct Answer";
        elements.imageList.children().length !== data.random &&
          (result = "Wrong Answer"), elements.output.text(result);
  // function invokes here