Skip to content

Instantly share code, notes, and snippets.

View steve54b's full-sized avatar

Steve Lokietz steve54b

  • Boca Raton, FL
View GitHub Profile
@steve54b
steve54b / votersim.rb
Created May 27, 2015 22:20
Voter Sim - $ ruby votersim.rb returns "votersim.rb:186: syntax error, unexpected keyword_end, expecting end-of-input"
##votersim.rb
class Person
attr_accessor :voters, :politicians
def initialize
@@voters = []
@@politicians = []
end
@steve54b
steve54b / gist:4d5321f01c93e783b974
Created May 28, 2015 02:15
Steve L votersim.rb
def test_voter_sim
person = Person.new
person.select_option
end
test_voter_sim
class Person
attr_accessor :voters, :politicians
def initialize
@@voters = []
@@politicians = []
end
def select_option
puts "in select_option"
##votersim.rb
class Person
attr_accessor :voters, :politicians
def initialize
@@voters = []
@@politicians = []
end
As the console output for this code demonstrates, the string "false" evaluates to
boolean false, so it is falsey - and 0 evaluates to 0, which is also regarded as falsey.
var z = 0;
console.log("z = " + z);
var not = "false";
console.log("not = " + not);
console.log("testing z && not");
console.log(z && not);
console.log("testing z || not");
The value between the two adjacent commas is shown as "undefined" in the response to entry of arr = [1,2,,4] (see section "1st "write some code"). However, as the answer to the 2nd part of this task (see below the dotted line) demonstrates, it appears that undefined equates to a null.
1st "write some code":
> arr = [1,2, ,4]
==> [1,2,undefined × 1,4]
> arr[1]
==> 2
>arr[2]
==> undefined
---------------------------
[1,2,undefined,4].toString() === [1,2,,4].toString()
The first block will:
1) output "do/while" to the console once
2) output "10" to the console once
3) decrement a from 10 to 9
4) execute whatever may be indicated in the
"while (a < 10 && a > 0)" loop until the "while" condition
is false (there is no indication of how the value of "a" will
be maniputlated, if at all, in the while loop.
The three lines within the second block's "while" loop will
result = 'Was it a car or a cat I saw?'.split('').reverse('').join('')
var asc = 0;
for (var i = asc; i <= 100; i+=10) {
console.log(i);
}
for (var i = 1; i <= 100; i++) {
if ((i % 5 === 0) && (i % 3 === 0)) {
fizzbuzz = "FizzBuzz";
} else if (i % 3 === 0) {
fizzbuzz = "Fizz";
} else if (i % 5 === 0) {
fizzbuzz = "Buzz";
} else {
fizzbuzz = i;
}