This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var asc = 0; | |
for (var i = asc; i <= 100; i+=10) { | |
console.log(i); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
result = 'Was it a car or a cat I saw?'.split('').reverse('').join('') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##votersim.rb | |
class Person | |
attr_accessor :voters, :politicians | |
def initialize | |
@@voters = [] | |
@@politicians = [] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
attr_accessor :voters, :politicians | |
def initialize | |
@@voters = [] | |
@@politicians = [] | |
end | |
def select_option | |
puts "in select_option" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_voter_sim | |
person = Person.new | |
person.select_option | |
end | |
test_voter_sim |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##votersim.rb | |
class Person | |
attr_accessor :voters, :politicians | |
def initialize | |
@@voters = [] | |
@@politicians = [] | |
end |
NewerOlder