• 0

my first script


Question

so I have a few questions here is the script

<body>
<script type="text/javascript" language="javascript">
x=prompt('please enter any amount of money you want.','500000')
if(x>=5)
{alert('you are very greedy please enter any amount less then 5 go wild the sky is the limit')
}
else{document.write('congratz won' + x)
}
</script>
</body>

Now I want the document write function to say

congratz you won x dollars but I dont now how to do that if I do

(document.write('congratz won' +x 'dollars') it does not work

also the alert box pops only once how do i get it to pop again some loop right because if the user continues to enter a number >5 he will have to continually try again

Please help this might be silly but its to learn at the end of the day

Link to comment
https://www.neowin.net/forum/topic/1199295-my-first-script/
Share on other sites

9 answers to this question

Recommended Posts

  • 0

I dont know a lot about javascript so you may need to make changes

 

have a look at this see if it helps

 

basically you want to DO the same thing until your answer is less than 5

do{
    var selection = parseInt(window.prompt("please enter any amount of money you want.", ""), 10);
}while(selection > 4);

so this would continuously ask for input until u enter a number less than 5

  • 0

OK thanks I tried a while loop like this

 

<script type="text/javascript" language="javascript">
x=prompt('please enter any amount you want.','5000')
while(x>=5)
prompt('you are too greedy please enter any amount less then 5.','4')
</script>
 
and got a perpetual loop I will try a do while loop like you suggested
  • 0
  On 05/02/2014 at 13:54, the better twin said:

 

You need to concatenate again after the variable and dont forget the spaces. In Javascript you use + as you already have done. 

document.write('congratz you won ' + x + ' dollars')

OK cool I am having trouble getting the loop though watching a video on the do while loop trying to get a handle on it 

  • 0
  On 05/02/2014 at 14:05, damindor said:

OK cool I am having trouble getting the loop though watching a video on the do while loop trying to get a handle on it 

Its effectively the same as a while loop but it will always run that one condition at least once. 

  • 0
  On 05/02/2014 at 14:09, the better twin said:

Its effectively the same as a while loop but it will always run that one condition at least once. 

I noticed so you get a prompt box to enter the amount you want even if its less then 5 the code will be excecuted at least once even if the value is >5

  • 0
  On 05/02/2014 at 14:23, damindor said:

I noticed so you get a prompt box to enter the amount you want even if its less then 5 the code will be excecuted at least once even if the value is >5

 

With a do/while loop, the code inside the loop will always get executed at least once. To make it work the way you want, you would only prompt the user inside the loop, and also check if the value is acceptable inside the loop. This code should give you an idea of what you should be doing:

var x = 10;
do {
    x = parseInt(prompt("Please enter any amount of money you want", "5000"));
    if (x >= 5) {
        alert("You are very greedy. Please enter any amount less than 5.");
    }
} while (x >= 5);

document.write("Congrats, you won $" + x);
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • In the case of the orange one it literally was just an Android app, someone already extracted it from the device and ran it on an android phone.
    • There were rumors of both - these third-party devices and a first-party Microsoft's handheld - the latter one was cancelled or postponed indefinitely. The difference is in licensing games - for a lot of thirdparty games Microsoft has distribution license only for consoles. I know that for some time already the hardware is the same, but legally they are totally different devices. That's why Microsoft wasn't on the hook for 30% cut from purchases on Xbox, but lowered its cut on Windows Store to just 12%.
    • Very true, they are trying to extract more revenue from viewers, and I agree with you that it will likely backfire on them and ultimately drive people to other platforms. I do think YouTube could ultimately win the battle against ad block if they want to, blocking ads is inherently significantly more complicated than enforcing them. We could easily get to a point where the best an ad-blocker can do is cover ads with a black screen while you wait out the deration. It isn't like software on your computer can force Google's servers to send the video content sooner than they deem appropriate. As for as dollars, I think you have your numbers mixed up a little. $29 is YouTube's revenue number, not worth or profit. YouTube being owned by Google means their worth and profit numbers are not directly known. Based on Google's reporting, it costs them more than YouTube's revue to run the platform. Maybe they are playing with the numbers a little, and certainly Google gets value from YouTube beyond direct revenue.
    • YouTube comments are not displaying correctly for some users by Aditya Tiwari Image by ElisaRiva via Pixabay YouTube comments have long been used to express opinions, ask questions, provide feedback, share insights, or simply react to the video you're watching. However, this can sometimes go south, and unexpected bugs can ruin the experience. The Google-owned video sharing platform reached out to its community support forum to announce that YouTube comments are not displaying correctly for some users. YouTube has listed various ways the known issue can appear on your screen. For instance, comments are only visible when the "Newest First" filter is chosen; they might disappear or hide when "Top Comments" is selected, or they may not display at all. Some users may not be able to sort comments by "Top Comments," or their comments may disappear after being posted. "We're aware that some of you are experiencing an issue where comments aren't showing up beneath certain videos, and we're looking into it now," YouTube said, adding that it will follow up on the issue with an update. However, it didn't mention the regions where the problem is most prominent or specify the platforms (Android, iOS, or desktop) that are affected. This comes about a week after YouTube ran into a different problem: the bottom navigation bar on its Android app wasn't displaying for users in different countries. YouTube has now marked that issue as fixed. In recent updates, the video streaming giant took down a video that taught people how to self-host their media, citing policy violations. Its latest update for iOS brings bad news for people running old iPhones; several of them are now incompatible with the YouTube app. While YouTube has introduced features like Google Lens for Shorts, voting for playlists, and trending podcasts charts, it plans to insert more ads into its cheaper premium tier later this month.
  • Recent Achievements

    • Enthusiast
      the420kid went up a rank
      Enthusiast
    • Conversation Starter
      NeoToad777 earned a badge
      Conversation Starter
    • Week One Done
      VicByrd earned a badge
      Week One Done
    • Reacting Well
      NeoToad777 earned a badge
      Reacting Well
    • Reacting Well
      eric79XXL earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      472
    2. 2
      +FloatingFatMan
      278
    3. 3
      ATLien_0
      246
    4. 4
      snowy owl
      204
    5. 5
      Edouard
      190
  • Tell a friend

    Love Neowin? Tell a friend!