My request for gig declined for some reason? No idea why


#1

Deploy micro-page with embeded json script.(fix and deploy code) I can’t attach .js/.html or even .zip of them for some reaason, and can’t copy and paste, so have put code in attached word document. It compiles and runs fine locally and on thimble. Once you click the run button. However I have used the window.alert for output. I can’t get it to run on the github .io pages. I just want a simple site (hosted anywhere) that will display the functionality, this runs locally and on thimble, however that gives you code down the side and requires you to excute manually. I want to have a website which will output the result of the code as soon as the url is accessed and has the code hidden from view much like the average site. You can change the display/output on the java file, but please don’t change the processing of the fizzbuzz,(even if yours is better :slight_smile: commented code on changes much appreciated. the html below and the js attached as a .txt


#2

I can’t attach the files here, but I did on fiverr site.

Hello World!

Check out the fizzbuzz test

// Initialize a string variable for the output
var output = ‘’;

// Count to 100 using i as the counter
for (var i = 1; i <= 100; i++) {

// If i is divisible by 3 with no remainder, append Fizz
if (i % 3 === 0) {
    output += 'Fizz ';
} 

// If i is divisible by 5 with no remainder, append Buzz
if (i % 5 === 0) {
    output += 'Buzz ';
}

// If i is not divisible by 3 or 5, append the number itself.
// Note: In JavaScript, non-zero integers are considered as
// truthy values, therefore if there's a remainder on both,
// we append the number instead.
if (i % 5 && i % 3) {
    output += i + ' ';
}

}

// Print the output to the console

window.alert(output);


#3

Hello World,

You haven’t attached your index file so I’ll just comment about what is available. Firstly, please check the syntax error in your string initialization ("").

Try any of these :

var silkroute = new String();

OR

var silkroute = '';

OR

var silkroute = "";

window.alert is not the most preferred form of output especially if you are hosting the app on the cloud and viewing it in the browser, as it is easy to overlook one of the zillion settings one has in today’s browsers (ad blocker, popup blocker, push alert blocker etc). In the specific case of Github, they require your JS to be hosted on their servers or you can host it on a separate branch within the app and reference the branch in your index file like a bawss.

Try any of these solutions :

  1. Instead of popping up the output, simply create an HTML element to display the output and pass the final output value into the HTML element. This will bypass all adblockers.

Right now, you are having to manually trigger the JS by clicking RUN on your compiler. In HTML, you will need to let the HTML do the triggering automatically.

This will solve the issue :

Use : innerHTML

BODY open

<script>
document.getElementById("demo").innerHTML = 3 + 5;
</script>

BODY close

This will solve your issue, read further only if you are interested in more ways to do it.

OR

  1. Or inject the output into the DOM of the page dynamically.

Use : document.write(silkroute)

OR

  1. Push the output directly into the browser console.

Use : console.log(silkroute)

One of the above (or most likely multiple of the above) will yield positive results for what you are trying to accomplish.

Another thing. When using comparisons try to use == instead of ===. The former does type conversions before doing comparisons, the latter does not do type conversions. It’s alright now because your app is simple, but as a habit, try to stick to ==.

Because,

If you are dealing with numbers and text, you might face a problem like this :

"silk" == new String("silk")    // true
"silk" === new String("silk")   // false

== shows true because it compares the values. << this is correct
=== shows false because it thinks they are different types of data << this can cause errors because you know it is “true”, you want it to output “true” but it disagrees with you and has its own opinion like a strong independent variable who need no man :joy:


#4

I couldn’t find a way to attach my index file. Fiverr refused attachments and if I add the html the forum just runs it. I should have just linked here. https://github.com/kraigh26/fizzbuzz

I did try console.log as well to no avail.


#5

In that case, have you tried turning it off and on back again? :joy:

I found the culprit. There are 2 actually.

  1. The print statement must be INSIDE the FOR LOOP to print it every time before moving on to the next iteration. At present, every time you run the FOR LOOP, the memory register for your variable ‘output’ gets flushed and overwritten by the next iteration of the FOR LOOP.

So, this is what is happening now :

Is 1 divisible by 3? NO, okay then output = null
Is 2 divisible by 3?, NO, okay then output = null
Is 3 divisible by 3?, YES, okay then output = null
Is 4 divisible by 3?, NO, okay then output = null

You see what’ I’m saying here?

All the while the numbers are being evaluated for their divisibility by 3 but if it is found to be divisible, then there is nothing in the code which makes it change the output. There is no feedback being sent to the variable output. It just sits there like, yo wassup dawg :

var output = ' ';

This is how it should be :

Is 2 divisible by 3? NO, okay output = null;
Is 3 divisible by 3? YES, okay, append Fizz to output and PRINT IT BEFORE moving on to asking if 4 is divisible by 3

I truncated the code to do this only for 3, added the JS in HTML itself, and got the output, you can do it for 5 as well, and you can do it for both 3 and 5 simultaneously using && operator. Just make sure your print statement is INSIDE the FOR LOOP and flush the output variable after every PRINT otherwise it will print elements from previous iteration again.

Here is a live demo of the working app. I’ve run it for 12 iterations, so it prints Fizz for (3,6,9,12)

Here’s the fully working JS code for 100 iterations, just wrap it inside HTML tags and your app is ready.

<script>
  var output = '';
  var i=0;
  
  for (var i = 1; i < 100; i++) 
  {  
    
    if (i%3 === 0) 
    {
        output += 'Fizz ' ;
        document.write(output);
        output= '';
    }
    if (i%5 === 0) 
    {
        output += 'buzz ' ;
        document.write(output);
        output= '';
    }
    
    
    if (i % 5 && i % 3) 
    {
    output += i + ' ';
    }
    
}
</script>


#6

cool, though before I read this I got it working with get element by ID :slight_smile: May I ask what application you are using in that screenshot?

document.write was restricted in my enviroment. Your script worked ok on github though.

https://kraigh26.github.io/fzbz/


#7

I’m using CodePen. Try Aptana IDE or Sublime. Both are equally good.

So, what was this assignment for? is this a college project?


#8

I read online that this test is becoming an increasing popular method of screening programmer/dev applications. I wanted an online app that showed I could build an app that would do that.
Since I haven’t done any javscript, it seemed as good a test as any. :relaxed: At least it wasn’t as bad as my college C# (I did the Fibonacci Sequence in an infinite loop (well until the variable ran out of memory then crashed.) :slight_smile: