[an error occurred while processing this directive] File: part2.html Creator: George Ferguson Created: Wed Oct 17 13:52:23 2012 Time-stamp: [an error occurred while processing this directive] File: templates/doc-start.shtml Creator: George Ferguson Created: Tue Dec 6 12:31:29 2011 Time-stamp: [an error occurred while processing this directive] File: site-settings.shtml Creator: George Ferguson Created: Tue Dec 6 13:49:49 2011 Time-stamp: Site (or subsite)-wide settings. [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] File: head.shtml Creator: George Ferguson Created: Tue Dec 6 12:34:15 2011 Time-stamp: SSI variables for this template: head_title if given, else ``sitename | title'' [an error occurred while processing this directive] File: head-title.shtml Creator: George Ferguson Created: Tue Dec 6 14:29:52 2011 Time-stamp: SSI variables for this template: head_title: complete content of title element if given site_title trailing part of title (if given) section_title middle part of title (if given) page_title leading part of title (if given) title title shown on page, also used as leading part of title (if given) [an error occurred while processing this directive] (none) [an error occurred while processing this directive] File: head-meta.shtml Creator: George Ferguson Created: Tue Dec 6 14:29:18 2011 Time-stamp: SSI variables for this template: meta_description meta_keywords meta_generator [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] File: head-stylesheets.shtml Creator: George Ferguson Created: Tue Dec 6 14:22:58 2011 Time-stamp: SSI variables for this template: site_stylesheet, page_stylesheet stylesheet0, stylesheet1, ...: URL for stylesheets [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] File: head-scripts.shtml Creator: George Ferguson Created: Tue Dec 6 14:23:19 2011 Time-stamp: SSI variables for this template: site_script, page_script script0, script1, ...: URLs of javascript scripts [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] File: body-start.shtml Creator: George Ferguson Created: Tue Dec 6 13:20:46 2011 Time-stamp: SSI variables for this template: body_class page_class page_id [an error occurred while processing this directive] [an error occurred while processing this directive] File: body-header.shtml Creator: George Ferguson Created: Tue Dec 6 13:46:12 2011 Time-stamp: Content above banner, if any.
Login
[an error occurred while processing this directive] File: body-banner.shtml Creator: George Ferguson Created: Tue Dec 6 13:27:12 2011 Time-stamp: Duplicate URCS Drupal banner. hajim urcs
Computer Science @ Rochester
Page Not Found : Department of Computer Science : University of Rochester Skip to main content
Rochester shield
  • Apply
  • Visit
  • Give

Search Rochester.edu

Hajim School of Engineering & Applied SciencesDepartment of Computer Science

Site Navigation

  • About Us
    • Overview
    • What is Computer Science?
    • Employment
    • History
      • 50th Anniversary
      • PhDs Conferred
      • In Memoriam
    • Engagement and Enrichment
    • Giving
    • Contact Us
  • People
    • Full Directory
    • Faculty
    • Graduate Students
    • Staff
  • Undergraduate
    • Overview
    • BS in Computer Science
    • BA in Computer Science
    • Minor and Clusters
    • Courses
    • Advising
    • Getting Experience
    • CS Lab Information
    • Applying
  • Graduate
    • Overview
    • Master's Program
    • PhD Program
    • Courses
    • Applying
  • Research
    • Overview
    • Computer Systems
    • Theory
    • Artificial Intelligence
    • Human-Computer Interaction
  • News & Events
    • Recent News
    • Seminars & Talks
    • Newsletter
    • Distinguished Gifts
    • Commencement

Page does not exist.

  • Overview
  • What is Computer Science?
  • Employment
  • History
    • 50th Anniversary
    • PhDs Conferred
    • In Memoriam
  • Engagement and Enrichment
  • Giving
  • Contact Us
  • Home
  • About Us
  • Contact Us

Missing page.

Sorry. The page you requested does not exist on the Department of Computer Science website

Return to the Computer Science Home Page

Report a Digital Accessibility Barrier

Department of Computer Science

Location
University of Rochester
2513 Wegmans Hall
P.O. Box 270226
Rochester, NY 14627
Phone
(585) 275-5671

Resources for

  • Prospective students
  • Current students
  • Parents & families
  • Faculty & staff
  • Alumni

Schools & divisions

  • School of Arts & Sciences
  • Hajim School of Engineering
  • Eastman School of Music
  • School of Medicine & Dentistry
  • School of Nursing
  • Simon Business School
  • Warner School of Education
  • Laboratory for Laser Energetics

Libraries & collections

  • University Libraries
  • Memorial Art Gallery

Helpful links

  • Intranet
  • Web Communications
  • Contact
  • Directory
  • Human resources
  • UR Mobile (app)
  • Parking & shuttles
  • Information technology
  • Blackboard
  • myURHR
  • MyPath

Ever better

  • Global engagement
  • Accessibility
  • Vision & Values
  • Office of University Engagement and Enrichment
  • Nondiscrimination & Title IX

More URochester

  • News
  • Events
  • Athletics
  • Arts
Two University of Rochester students working on an experiment in a lab.Exterior profile of the University of Rochester’s Eastman School of Music. University of Rochester student plays the violin during a concert.
  • Facebook
  • YouTube
  • X / Twitter
  • TikTok
  • Instagram
  • LinkedIn
  • Threads
  • Follow URochester
Three University of Rochester sophomores posed together while wearing University of Rochester hats. The University of Rochester Rush Rhees Library bell tower at sunrise. Close up of a therapy dog’s nose on the University of Rochester river campus.
University of Rochester logo
  • Contact us
    (585) 275-2121
  • See maps and directions
    Rochester, NY

Search Rochester.edu

  • Privacy
  • Copyright
  • Emergency Information

© University of Rochester 1996–2026

[an error occurred while processing this directive] File: body-title.shtml Creator: George Ferguson Created: Tue Dec 6 14:34:49 2011 Time-stamp: SSI variables for this template: section_name First line of title on page (if any) title Title shown on page

[an error occurred while processing this directive] CSC170: Introduction to Programming and the Web
Fall 2012
[an error occurred while processing this directive]
Assignment 6: Functions, Part 2

  1. [2 pts] Write a script with two global variables: count and total. Write a function with a local variable count that does the following:
    1. Increments count by one;
    2. Asks the user for a number using the current value of count in the prompt;
    3. Adds the number to total;
    4. Adds a line with the current values of count and total to the document.
    The main body of your script should call the function three times. After the first call, it should set count to 10. After the second call, it should set total to 42.

    Warning: Your program's behavior may be strange. You should understand why.

  2. [4 pts] This question was made optional Sun Oct 21. See the BB announcement for further details and discussion.

    In Javascript, the method String.charAt(i) returns the character at the i'th position in a string, starting at 0 for the first character. For example:

          var s = 'Fred';
          document.write(s.charAt(0));
        
    This will produce the single character F (with no quotes). Try it. (Technically it's a string of length one; Javascript doesn't have a character data type.) Similarly, s.charAt(1) would be the single character r, s.charAt(2) would be e and s.charAt(3) would be d. We'll see more about these built-in methods soon, but for now let's just use it to get characters from strings.

    Write a recursive function that accepts a string as its only parameter and returns the string which is the reverse of the original string. For example on input Fred, it would return derF. Illustrate your function on a page that asks the user for a string and displays it and its reverse.

  3. [4 pts] Pawlicki's function, written P(n) in math, is defined as the sum of terms -i(i-1) where i ranges from 1 to n. In mathematical notation, that would be:
    1. Write a Javascript function that computes Pawlicki's function for a given number using iteration (that is, some kind of loop).
    2. Write a Javascript function that computes Pawlicki's function for a given number using recursion.
    Demonstrate both versions using pages that ask the user for a number and display the number and the result of the function. You could also use a single page that calls the two versions of your function and reports the results. In that case, you would need to give the functions different names, of course.

    Note/Hint: You might want to use a pow(x,n) function like we saw in class to do the exponentiation.

Things to think about

  • Don't forget that every function you define should come with a comment that explains its purpose (briefly), its arguments, and its return value.
  • Variable scoping problems are the source of many, many Javascript errors. Be very careful with variable declarations (var statements) to minimize problems.
  • There is a subtle and powerful relationship between iteration and recursion. Many functions can be implemented either way. For what it's worth, recursion is usually more elegant but iteration is usually faster. In fact, in compiled programming languages, the compiler can sometimes replace recursion with iteration automagically. However not all recursive algorithms can be easily implemented using iteration.

[an error occurred while processing this directive] File: doc-finish.shtml Creator: George Ferguson Created: Tue Dec 6 13:46:48 2011 Time-stamp: [an error occurred while processing this directive] File: body-footer.shtml Creator: George Ferguson Created: Tue Dec 6 14:43:56 2011 Time-stamp: Content at bottom of page, if any.

Last update: Monday, 22-Oct-2012 09:41:09 EDT

Department of Computer Science · University of Rochester
734 Computer Studies Bldg. · P.O. Box 270226 · Rochester, NY 14627
tel: 585 275-5671 · fax: 585 273-4556 · info@cs.rochester.edu
Hajim School of Engineering and Applied Sciences
[an error occurred while processing this directive] File: body-finish.shtml Creator: George Ferguson Created: Tue Dec 6 13:47:36 2011 Time-stamp: [an error occurred while processing this directive]