Fundamentals of NewtonScript

Exercises

1. In the Inspector, write a function that takes an array as a parameter and returns a new array that contains the elements in reverse order. For example:

myFunctions:ReverseArray([3, 5, "abc"]) 
--> ["abc", 5, 3]
A QuickTime movie of the solution is available.

2. In the Inspector, write a function that takes an array of numbers as a parameter and returns the total of the numbers. For example:

myFunctions:TotalOfArray([3, 5, 7]) --> 15
A QuickTime movie of the solution is available.

3. In the Inspector, write a function that takes as a parameter a frame whose slots contain numbers and returns the total of the numbers. For example:

myFunctions:TotalOfFrame({x: 7, y: 16, z:20}) --> 43
A QuickTime movie of the solution is available.

4. In the Inspector, create a frame object containing a Next method that returns successive odd numbers. For example:

oddNumbers:Next() --> 1
oddNumbers:Next() --> 3
oddNumbers:Next() --> 5
A QuickTime movie of the solution is available.

5. In NTK, create an application that contains a text button. Tapping on the button should print out the current date and time to the Inspector.


Hint:Time() returns the current date and time as an integer. DateNTime(Time()) returns a string containing the current date and time in human-readable form.


A QuickTime movie of the solution is available, as is the completed project for different platforms (Mac OS, Windows 3.1 or Windows 95/NT).


An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996