You must hand in by using git
bitbucket.org,
gitlab.com, or
github.com,
git push your local repo to the above remote repo.
node_modules/
.gitignore file.
Send a mail to <nmla@iba.dk> with:
handin <subjectname>'
in the subject line of your mail
Definition
A natural numberpis called prime ifp ≠ 1and the only numbers that dividepare 1 andpitself.
Fundamental Theorem of Arithmetic
Every natural number greater than 1 is either prime or can be written uniquely as a product of prime numbers.
There is a nice proof of that theorem but since this is no math class, we shall skip that, and just trust that it is so, and use it.
Now you must solve at least number 1 of the following. If you have the energy and skill you may want to have a go at the next ones too, but please solve the rest of this chapter's assignments before spending time on that.
isPrime(p) that returns
true if p is prime, and
false otherwise.
p
if isPrime(p) === false.
p
if isPrime(p) === false.
p more than once.
Write an HTML5 page that allows for testing your function(s).
Hint for beginners:
You may prefer to work with embedded JavaScript while you
test your code. Once it works as desired, separate the JavaScript into an
individual .js file, test again, then hand in your
solution.
jsloops71.js
[Dow16] Exercise 7.1
'use strict';
/* Downey: thinkjava, ex 71 */
const loop = function(n) {
let i = n;
while (i > 1) {
console.log(i);
if (i % 2 == 0) {
i = i / 2;
} else {
i = i + 1;
}
}
}
loop(10);
i and n
during the execution of loop.
The table should contain one column for each variable and
one line for each iteration. You might trick the program
into doing it for you.
[Hav19] Exercise FizzBuzz, chapter 2.
Write a program that uses console.log to print all the numbers
from 1 to 100, with two exceptions.
For numbers divisible by 3, print "Fizz" instead of the
number,
and for numbers divisible by 5 (and not 3), print "Buzz"
instead. Save as fizzbuzz.js.
When you have that working, modify your program to print
"FizzBuzz" for numbers that are divisible by both 3 and 5
(and still print "Fizz" or "Buzz" for numbers divisible by only
one of those). Save as fizzbuzzBetter.js.
(This is actually a job interview question that has been claimed
to weed out a significant percentage of programmer candidates.
So if you solved it, your labor market value just went up.)
Write an iterative function powi(r, e)
that calculates
the e-th power of r, re.
Document it with a couple of testcases.
Save the function in myFuncLib.js.
Write an iterative function facti(n)
that calculates n!.
Document it with a couple of testcases.
Save the function in myFuncLib.js.
We have flipped coins and dies 10 times. I want you to change
the code so that the user may enter the number of times she
wants to play dice, say 25, 1000, or even 100000000.
Write a jsPlay75.html that does that, and of course
uses the function we created earlier.
Change the program so that user can choose between flipping coins, rolling dice, playing roulette, etc.
Save them in a repo games.