Exercise 1
let a=prompt (“hello, choose a number”);
let b=prompt (“hello, choose another number”);
function minimum(a,b)
{if (a>b) return("the minimum is “+b);
else return"the minimum is “+a};
document.write(minimum(a,b)+”\n”);
Exercise 2
let n=prompt (“hello, choose an even number”);
function isEven(n)
{if (n == 0) return true;
else if (n == 1) return false;
else if (n<0)return isEven(-n);
else return isEven(n - 2)};
document.write("the number is "+isEven(n))
Exercise 3
I am stuck with this one, even when reading the solution i dont understand it.
I dont understand the string and charecter…
You can get the Nth character, or letter, from a string by writing “string”[N].
The returned value will be a string containing only one character (for example,
“b”). The first character has position 0, which causes the last one to be found at
position string.length - 1. In other words, a two-character string has length
2, and its characters have positions 0 and 1.
Write a function countBs that takes a string as its only argument and returns
a number that indicates how many uppercase “B” characters there are in the
string.
Next, write a function called countChar that behaves like countBs, except
it takes a second argument that indicates the character that is to be counted
(rather than counting only uppercase “B” characters). Rewrite countBs to
make use of this new function.
Could anyone explain it to me?