wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const index = 35; index = 38;
let index = 35; index = 38;
Cannot reassign const.
JavaScript
if b = 11 then print('value') end
if b == 11 then print('value') end
Use ==.
Lua
list[33]
if list.indices.contains(33) {{ list[33] }}
Check index.
Swift
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
class Person {{ int index; }} obj.index=5;
class Person {{ public int index; }} obj.index=5;
Make field public.
Java
{{'title':77, 'name' 64}}
{{'title':77, 'name':64}}
Colon missing.
Python
int arr[75]; arr[75]=5;
int arr[75]; if(75<75){{}} else arr[75]=5;
Bounds check.
C++
[x*x for x in data if x > 35]
[x*x for x in data if x > 35]
Correct list comprehension.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
cin >> val;
int val; cin >> val;
Declare variable.
C++
if b > 61 print('test')
if b > 61: print('test')
Colon missing after if.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<note name='world'/>
<note name="world"/>
Double quotes.
XML
items[86]
if (length(items) >= 86) items[86]
Check length.
R
switch(temp){{ case 48: break; }}
switch(temp){{ case 48: break; default: break; }}
Add default case.
Java
if (foo = 100) {}
if (foo == 100) {}
Use ==.
Dart
if (x = 27)
if (x == 27)
Use ==.
Scala
else print('world')
else: print('world')
Colon after else.
Python
[66, 40, 43
[66, 40, 43]
Close bracket.
Ruby
object Product {{ def main(args: Array[String]) = println("output") }}
object Product {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
let result: i32 = "output";
let result: &str = "output";
Type mismatch.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(59);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(59, () => console.log('listening'));
Add callback.
Node.js
def bar(count): return count + 1
def bar(count): return count + 1
Correct.
Python
var x = 39;
var x = 39;
Correct.
Dart
if (y = 93)
if (y == 93)
Use ==.
R
function baz() {{ return {{key:'test'}} }}
function baz() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
$data = 40; if ($data = 40) {{}}
$data = 40; if ($data == 40) {{}}
Use ==.
PHP
["hello", 28]
["hello", 28]
Correct.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if ($x = 84)
if ($x == 84)
Use ==.
Perl
let y: number | null = null; y.toFixed(66);
let y: number | null = null; if(y!==null) y.toFixed(66);
Null check.
TypeScript
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
print 'value'
print 'value';
Add semicolon.
Perl
if x = 19
if x == 19
Use ==.
Go
<p>value <b>hello</p></b>
<p>value <b>hello</b></p>
Nest properly.
HTML
// comment
/* comment */
Use /* */.
CSS
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (b = 7) {{}}
if (b == 7) {{}}
Use ==.
Kotlin
yield bar
yield bar
Correct yield.
Python
$data[55] = 5;
if (isset($data[55])) $data[55] = 5;
Check existence.
PHP
<person age=5>
<person age="5">
Quote attribute.
XML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if x = 18
if x == 18
Use ==.
Ruby
let b = 'data'
let b = "data"
Double quotes.
Swift
String b = 'info';
String b = "info";
Double quotes.
Java
fn handle() -> i32 {{ 55 }}
fn handle() -> i32 {{ 55 }}
Correct.
Rust
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if foo = 21 {{}}
if foo == 21 {{}}
Use ==.
Swift
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
re.sqrt(20)
import re re.sqrt(20)
Import module first.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
if (item = 79) {{}}
if (item === 79) {{}}
Use === for equality.
JavaScript
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
if index > 99 puts 'test'
if index > 99 puts 'test' end
Add 'end'.
Ruby
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
val == '82'
val === 82
Use strict equality.
JavaScript
let list=vec![70,87,12]; let first=&list[0]; list.push(48);
let mut list=vec![70,87,12]; let first=list[0]; list.push(48);
Copy instead of reference.
Rust
List(66,6,98)
List(66,6,98)
Correct.
Scala
list(83)
if length(list) >= 83, list(83), end
Check length.
MATLAB
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
while data > 8 data -= 1
while data > 8: data -= 1
Colon missing after while.
Python
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for b in range(36) print(b)
for b in range(36): print(b)
Colon after for.
Python
assert count > 60
assert count > 60
Correct.
Python
{{'age':'message'}}
{{"age":"message"}}
Use double quotes.
JSON
if item = 8:
if item == 8:
Use == for comparison.
Python
DELETE FROM products WHERE id=9
DELETE FROM products WHERE id=9;
Add semicolon.
SQL
INSERT INTO items VALUES ('test',99)
INSERT INTO items (age, status) VALUES ('test',99);
Specify columns.
SQL
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
String name = 'value';
String name = 'value';
Correct.
Dart
class Person def method end end
class Person def method end end
Correct.
Ruby
let s = String::from("info"); let r=&s; s.push_str("!");
let mut s = String::from("info"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function compute(c:string){{return c;}} compute(60);
function compute(c:string){{return c;}} compute('hello');
Pass correct type.
TypeScript
<input type='text' value='hello'>
<input type='text' value='hello' name='age'>
Add name attribute.
HTML
SELECT * FROM orders WHRE email=78;
SELECT * FROM orders WHERE email=78;
Fix WHERE.
SQL
index = 53
index=53
No spaces.
Shell
val foo: Int = 'result'
val foo: String = 'result'
Fix type.
Kotlin
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
{{"title":"message" "status":32}}
{{"title":"message", "status":32}}
Add comma.
JSON
{{"name":"info",}}
{{"name":"info"}}
Remove trailing comma.
JSON
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
let a: number = 'result';
let a: string = 'result';
Fix type.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
[94, 51, 86
[94, 51, 86]
Close bracket.
Python
83count = 10
count83 = 10
Variable cannot start with digit.
Python
if [ $x = 82 ]; then
if [ "$x" = 82 ]; then
Quote variable.
Shell
UPDATE users SET name='output' WHERE email=22
UPDATE users SET name='output' WHERE email=22;
Add semicolon.
SQL
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS