I need help. I am taking an intro course in JS and I need help with some practice questions from my textbook that I can't get to work on my computer.
I have to write 3 functions with while loops in them. One to count the number of whitespaces in a string (my teacher recommended accessing it like an array but I haven't been able to do that), one that takes in two numbers and sees how many times the first goes into the second by adding, and the last one is to see if an array contains any positive numbers. My code is below for what I have done. I appreciate any guidance and assistance. Thanks!
Code:
count = 0;
var i = 0;
function howManySpaces(input)
{
while(i < input.length-1){
if {(howManySpaces[index] = '')
count++;
i++ }
else {
i++ }
}
}
Code:
var count=0;
var c=0;
function howManyFit(a, b) {
while ((b - c) >= a){
c = c + a;
count++;
}
return count;
}
Code:
Nothing for the positive check. I've been playing around with the modulus but haven't gotten it to work at all.
03-03-2013, 12:10 PM
jinjinodie
Edit: The last function returns false if there is a negative or 0 in the array
03-03-2013, 04:33 PM
Avdon
Hello
Code:
count = 0;
var i = 0;
function howManySpaces(input)
{
while(i < input.length-1){
if {(howManySpaces[index] = '')
count++;
i++ }
else {
i++ }
}
}
I think the next part is completly wrong
Code:
if {(howManySpaces[index] = '')
- There is no argument for the "if". if (arguments) {code to excute}.
-There is no array named "howManySpaces".
- "index" is undefined.
-'' indicate empty. Space ' '.
I think the code could be something like: