Assignments JS.1

Handing In Assignments

You must hand in by using git

Hand In by git

  • Create an empty repo on bitbucket.org, gitlab.com, or github.com,
  • git push your local repo to the above remote repo.
  • For node assignments please put the line(s)

    node_modules/

    into your .gitignore file.

Send a mail to with:

  • The word 'handin <subjectname>' in the subject line of your mail
  • The url of your repo(s).

A remark

The following assignments/exercises are meant to train programmatic thinking and coding essential for coding in any programming language. Here we use JavaScript. You may have various degrees of coding experience from earlier studies. From that you may be familiar with if's or various loop constructs. Today's assignments must be solved without any of those. The techniques used in the examples of today's chapter should be sufficient.

We will of course get to if's and loops very soon.

Assignment JS.15

Write a program into a file called js15.js.

The program must accept input of a number from the user. Assume the number is the temperature in Fahrenheit. Your program must convert the temperature to Celsius and print it on the console.

The conversion formula is c = 5/9(f-32) where c is the result in Celsius, and f is the temperature in Fahrenheit.

Assignment JS.20

Write a program into a file called js201.js.

The program must accept input of a number from the user. Assume the number is a year. Make JavaScript write on the console true or false as to whether the year is a leap year or not. If you don't know what a leap year is, Google it.

Write another program into a file called js202.js.

The program must accept input of a number from the user. Assume the number is a CPR number (a danish social security number). Make JavaScript write on the console true or false as to whether the person holding the number is a woman.

Assignment JS.25

In todays lesson, re Example 2.7, there was an example of letting JavaScript print the truth table for a negation on the console.

  • Create a similar example in a file, js25c.js for printing the truth table for the conjunction.
  • Then create another file, js25d.js with the code for printing the truth table for the disjunction.

You will have noticed that a conjunction/disjunction of two questions have four possible outcomes, each condition may be true or false. Two conditions, 2 x 2 possible outcomes.

Three conditions that could each result in true or false thus gives you 2 x 2 x 2 = 8 possible outcomes.

  • Create another file, js25c3.js for printing the truth table for a conjunction of 3 conditions: var1, var2, and var3.
  • Then create yet another file, js25d3.js with the code for printing the truth table for a disjunction with three conditions.

For the latter two, it may be very helpful to visualize by drawing them on paper first.

Assignment JS.30

Predict the results of

8 / 2 * (2 + 2)     // ?
8 / 2 * 2 + 2       // ?

Then let JavaScript solve it. Print the result on the console. Hand in as a file called js30.js