Comp 416 – Web Programming

University of North Carolina at Chapel Hill

Shuffle 'Em Up

  • Assigned: W 9/26
  • Due: W 10/3
  • Possible Points: 3

Description

Our future Electronic Flashcard assignment will show the user a set of independent problems to solve. Each is one electronic flashcard. On the page is a 'shuffle' button that randomly reorders the problems on the page. For example, here are screen shots before and after the shuffle button is pressed.

In this assignment, we will write the JS code to create the random permutation of the problem numbers. This assignment will not reorder the HTML elements on a page. That is for a future assignment.

Suppose we have 5 electronic flashcards. We represent this by a 5 element array [ 1, 2, 3, 4, 5 ]. You will write a JS function function shuffle(x) that is passed the array of problem numbers and randomly permutes its values. For example, the following

        var x = [ 1, 2, 3, 4, 5 ] ;
        shuffle( x );
        console.log( x )
        
        may produce the output
        
        4, 5, 2, 3, 1
         

Requirements

Copy the skeleton and add you JS code. You do not have to write any HTML or CSS code for this assignment. The shuffle function repeatedly permutes 2 random elements of the array. The number of permutations should be (approximately) equal to the length of the array. You are provided with a function that returns random integers.

Turn in the following in the following order:
  1. Cover page.
  2. JS code
  3. Output of running testShuffle (from FB console window)

Grading

  • 55% Correctness
  • 35% Thoroughness of testing
    10% Good coding style: use of descriptive names, proper indentation,etc.

Objectives

Write your first Javascript program: functions, parameters, arrays, lops, testing.