Jump to content
Chumpy

is this a real editor or just case specific

Recommended Posts

I have entered "Math.floor(Math.random() * number) into a switch statement, an if statement, among others, and it doesn't work.  Maybe the editor is looking for specific case related code or switch or if just doesn't like this method?

Share this post


Link to post
Share on other sites

How about you post some code for us to look at your implementation. It may be some obscure JavaScript thing tripping it up.

XcQfW3F.png

Share this post


Link to post
Share on other sites

Your request is very unclear, but just to prove that you code can be used in a 'switch' statement,
consider this:

<!DOCTYPE html><html lang="en"><head><title> Test Page </title>
<meta charset="UTF-8">

<meta name="viewport" content="width-device-width,initial-scale=1.0, user-scalable=yes"/>

<!-- link rel="stylesheet" href="common.css" media="screen" -->
<style>

</style>

</head><body>
<button onclick="rnd5()">Test</button>
<pre id='demo'></pre>

<script>

function rnd5() {
  var number = 9;
  var r = Math.floor(Math.random() * number);
//  document.getElementById('demo').innerHTML = r+'\n';  // Simple display
  switch (r) {
    case 0: document.getElementById('demo').innerHTML += `Number generated by switch was: ${r}\n`; break;
    case 1: document.getElementById('demo').innerHTML += `Number generated by switch was: ${r}\n`; break;
    case 2: document.getElementById('demo').innerHTML += `Number generated by switch was: ${r}\n`; break;
    case 3: document.getElementById('demo').innerHTML += `Number generated by switch was: ${r}\n`; break;
    case 4: document.getElementById('demo').innerHTML += `Number generated by switch was: ${r}\n`; break;
    case 5: document.getElementById('demo').innerHTML += `Number generated by switch was: ${r}\n`; break;
    case 6: document.getElementById('demo').innerHTML += `Number generated by switch was: ${r}\n`; break;
    case 7: document.getElementById('demo').innerHTML += `Number generated by switch was: ${r}\n`; break;
    case 8: document.getElementById('demo').innerHTML += `Number generated by switch was: ${r}\n`; break;
  }
}

</script>

</body></html>

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...