Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

JS - anyone able to help teach me? need assistance with assignments


  • Please log in to reply
5 replies to this topic

#1 traptack

traptack

  • Members
  • 49 posts
  • OFFLINE
  •  
  • Local time:03:44 PM

Posted 28 February 2013 - 01:57 AM

or at least walk me through problems?  I'm currently taking a college class right now, basically intro to computer science, but i'm still struggling, struggling in that I have difficulty combiining concepts and also remembering them.I notice I often have to look back to previous stuff. ANyhow my class has weekly assignments that are due at the end of each week, and lately I've had a harder time understanding things.

 

 

Currently in javascripting it's been  while/for looping, functions and what not.

we also use code academy, but i've stumbled arcoss a problem that I don't know how to solve, which is rare on code academy for me.

 

 

Write a while loop that logs "I'm looping!" to the console three times. You can do this however you like, but NOT with three console.log calls. Check the Hint if you need help!

 

 

this is what I have so far

 

 

//Remember to make your condition true outside the loop!
var loop = true;
var loop = function(round){
    while(loop < 3){
        console.log("i'm looping");
        loop = false;
    }
};

round(9);

 

 

I use w3schools.com as well for a resource but the definitions only help to an extent, they don't provide enough broad examples for me :\


Edited by traptack, 28 February 2013 - 02:01 AM.


BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Moderator
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:44 PM

Posted 28 February 2013 - 09:14 AM

Here are a couple of problems: You have a variable and an anymous function both named loop. You do not have a function called 'round', but you are calling it at the end. Also, you are setting your sentinel to false every time at the bottom of the loop, which is logically equivalent to a zero. My guess is that you would end up in an infinite loop.

 

This is a 3 line bit of code. You should be able to easily find examples by googling 'Javascript while' or 'javascript if'.



#3 traptack

traptack
  • Topic Starter

  • Members
  • 49 posts
  • OFFLINE
  •  
  • Local time:03:44 PM

Posted 28 February 2013 - 10:58 PM

Here are a couple of problems: You have a variable and an anymous function both named loop. You do not have a function called 'round', but you are calling it at the end. Also, you are setting your sentinel to false every time at the bottom of the loop, which is logically equivalent to a zero. My guess is that you would end up in an infinite loop.

 

This is a 3 line bit of code. You should be able to easily find examples by googling 'Javascript while' or 'javascript if'.

 

 

I really sdon't get the sentinel true and false part of the while loop.

dang this should only be in three lines? :\



#4 groovicus

groovicus

  • Moderator
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:44 PM

Posted 01 March 2013 - 07:14 AM

I told you what to search for. It is the first result. :blink:

 

You can do this problem in 3 lines. You can also probaby do it in 10 or 30 lines.



#5 traptack

traptack
  • Topic Starter

  • Members
  • 49 posts
  • OFFLINE
  •  
  • Local time:03:44 PM

Posted 01 March 2013 - 12:53 PM

I told you what to search for. It is the first result. :blink:

 

You can do this problem in 3 lines. You can also probaby do it in 10 or 30 lines.

:lmao:

no don't worry- I saw that page you were trying to get me to look at, I saw it and tried to but idk it hasn't worked out for me yet.



#6 lhamil64

lhamil64

  • Members
  • 200 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:United States
  • Local time:07:44 PM

Posted 12 March 2013 - 10:02 PM

I will try to help, even though I haven't worked specifically with Javascript too much, concepts like 'while' loops are basically the same in every language.
 
The basic structure of a while-loop is:
 
 
 

while( condition ){
    <do stuff>
}
 

The 'condition' part is some boolean expression (something that comes out being either true or false). The while-loop will keep looping until the 'condition' becomes false. In your example, it will stop running when the 'loop' variable is greater than 3.
 
As the previous post said, there are some problems though. The first one I noticed, why are you doing this inside a function? For something this simple, you can completely remove the function and put the while-loop right in. Really, your while-loop itself looks perfect, but because it's in a function (which is declared somewhat wrong), it wont run. Since you're still learning about loops, I'm assuming you aren't required to use functions, so I would just remove it completely.
 
If you want to see the solution (I'd recommend trying it some more yourself so you aren't just seeing the answer), I will put it in the spoiler tags below.


Edited by groovicus, 13 March 2013 - 06:18 AM.
removed solution. We do not provide solutions to people's homework problems.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users